SoFunction
Updated on 2025-04-13

From the classic to create a simple PHP&MYSQL message board page 3/4


<?php
require_once("");
$username = $_POST['name'];
$sex = $_POST['sex'];
$qq = $_POST['qq'];
$email = $_POST['email'];
$info = $_POST['info'];

if (strrpos($username,"<")!==false || strrpos($username,">")!==false||strrpos($username,"@")!==false||strrpos($username,"\"")!==false||strrpos($username,"'")!==false||strrpos($username,"_")!==false)
{
echo "<script>alert('The name cannot have special characters!');='';</script>";
    exit();
}

if (!ereg("^[0-9]{0,}$",$qq))//Check the QQ format with regularity
{
echo "<script>alert('There is an error in the OICQ information! It must be a number!');='';</script>";
    exit();
}

if($email)
{//If you fill in the email, use regular checking the email format
    if (!ereg("^[a-zA-Z0-9_\-\.]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$",$email))
    {
echo "<script>alert('email format is incorrect!');='';</script>";
        exit();
    }
}

if(!$username)
{
echo "<script>alert('The name cannot be empty!');='';</script>";
    exit();
}
elseif(!$info)
{
echo "<script>alert('The message cannot be empty!');='';</script>";
    exit();
}
else
{
$ip = getenv('REMOTE_ADDR');//Get client IP address

    $sql = "insert into lo (username,sex,qq,email,info,ip,submit_time) values ('$username','$sex','$qq','$email','$info','$ip',NOW())";

    $result = mysql_query($sql);

    mysql_close();

echo "<script>alert('Submission was successful! Return to homepage');='';</script>";
}
?>