$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="members"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
$repeatpassword=$_POST['repeatpassword'];
// To protect MySQL injection (more detail about MySQL injection)
$myusername = strip_tags($myusername);
$mypassword = strip_tags($mypassword);
$repeatpassword = strip_tags($repeatpassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$repeatpassword = mysql_real_escape_string($repeatpassword);
if($myusername&&$mypassword&&$repeatpassword)
{
if ($mypassword==$repeatpassword)
{
if (strlen($myusername)>10)
{
header("location:erroruname.php");
}
else
{
if (strlen($mypassword)>10||strlen($mypassword)<5)
header("location:errorpword.php");
else
{
$queryreg = mysql_query("
INSERT INTO $tbl_name VALUES('','$myusername','$mypassword')
");
session_register("myusername");
session_register("mypassword");
header("location:insertdetail.php?myusername=" . $username);
}
}
}
else
header("location:errornomatch.php");
}
else
header("location:errorfields.php");
答案 0 :(得分:2)
由于您未在INSERT
INSERT INTO $tbl_name VALUES('','$myusername','$mypassword')
需要看起来像
INSERT INTO $tbl_name(`column_a`, `username`, `password`)
VALUES('','$myusername','$mypassword')
答案 1 :(得分:1)
该表中是否有自动增量列?如果是这样,请不要使用' '
,而是不要输入任何内容。在这种情况下,应该只指定两列(用户名和密码)。
答案 2 :(得分:0)
回显查询并在phpmyadmin中手动运行sql查询
echo "INSERT INTO $tbl_name VALUES('','$myusername','$mypassword') "; die();