我确实有一个名为“id”的附加列,但它是一个带有自动增量的主键,如果我把它放在值中,它会添加id,但是firstname数据总是0,firstname数据输入lastname,姓氏数据输入用户名,用户名数据进入电子邮件字段,电子邮件数据输入密码字段,密码数据进入确认密码字段,最后确认密码数据和国家数据进入国家字段。以下是我的代码 ?>
<?php
//connection to the database server
$hostname="localhost";
$user="root";
$password="";
$connection = mysql_connect($hostname, $user, $password) or die ("cannot connect to mysql database server");
//selection of database
mysql_select_db("jewelgallery", $connection) or die ("cannot reach jewelgallery database");
$firstname = $_POST['firstName'];
$lastname = $_POST['lastName'];
$username = $_POST['username'];
$email = $_POST['email'];
$password1 =$_POST['password'];
$password2 =$_POST['confirmPassword'];
$country =$_POST['country'];
$sql2="select * from customer_account where username = '$username'";
$results = mysql_query($sql2, $connection) or die(mysql_error());
$numOfRecords1 = mysql_num_rows($results);
$_SESSION["username"] = $username;
if ($numOfRecords1 != 0)
{
echo "<h3>This Username ". $_SESSION["username"]." Has been chosen by another user</h3> <a href=registercustomer.html> Please Try Again </a>";
header("Refresh:5;url=registercustomer.html");
exit;
}
$sql="insert into customer_account(firstname, lastname, username, email, password, confirmpassword, country)
Values('$firstname', '$lastname', '$username', '$email', '$password1', '$password2' '$country')";
mysql_query($sql, $connection) or die(mysql_error());
mysql_close($connection);
echo "Registration Successful. <a href=../index.html> Continue </a>";
header("Refresh:5;url=../index.html");
?>
答案 0 :(得分:3)
你错过了一个逗号:
'$password2' '$country')";
^^^^^
HERE
修正:
$sql="insert into customer_account(firstname, lastname, username, email, password, confirmpassword, country)
Values('$firstname', '$lastname', '$username', '$email', '$password1', '$password2', '$country')";