我无法弄清楚我的 PHP 有什么问题,但 INSERT 函数似乎总是失败。我列出了正确的表行,但可能只是一个简单的语法问题。如果需要该代码,我也可以提供。这是我的 PHP 和数据库结构:
<?php
$con = mysql_connect('***','***','***');
if (!$con)
{
echo "Failed to make connection.";
exit;
}
$db = mysql_select_db('***');
if (!$db)
{
echo "Failed to select db.";
exit;
}
$username = $_POST['username'];
$password = $_POST['password'];
$name = $_POST['name'];
$email = $_POST['email'];
$sql = "SELECT username,email FROM Users WHERE username = '" . $username . "' OR email = '" . $email . "'";
$query = mysql_query($sql);
if (mysql_num_rows($query) > 0)
{
echo "That username or email already exists";
}
else
{
$insert = "INSERT INTO Users(username,password,name,email) VALUES ('" . $username . "','" . $password . "','" . $name . "','" . $email . "')";
$query = mysql_query($insert);
if ($query)
{
echo "Thanks for registering. You may now login.";
}
else
{
echo "Insert failed";
}
}
?>