PHP - 无法将值插入MySQL数据库

时间:2017-10-23 18:36:39

标签: php mysqli

检查所有引号,语法,在这里搜索一些问题,仍然出现问题。不知道该怎么办。我的代码如下:

<?php   
//connect to database
$db = mysqli_connect('localhost', 'root', '', 'ticketing');

if (isset($_POST['submit'])) 
{
session_start();
    $username = ($_POST['username']);
    $email = ($_POST['email']);
    $password =($_POST['password']);
    $re_type = ($_POST['re_type']);

    if ($password == $re_type)
    {
        //create user
        $sql = "INSERT INTO registration VALUES ('$_POST[username]','$_POST[email]','$_POST[password]','$_POST[re_type]')";
        mysqli_query($db, $sql);
        $_SESSION['message'] = "You are now logged in";
        $_SESSION['username'] = $username;
        $_SESSION['email'] = $email;
        $_SESSION['password'] = $password;
        $_SESSION['re_type'] = $re_type;
        header("location:waley.php"); //redirect to homepage
    }

    else
    {
        $_SESSION['message'] = "The two passwords do not match";
    }
}
?>

PS。抱歉我的英文不好

0 个答案:

没有答案