我正在为网站创建注册页面。当我提交表单时,数据不会发送到数据库。有人知道为什么会这样吗?以下代码来自名为register.php的脚本我不明白为什么它不会发送到我的mysql数据库。昨晚我有一个错误“phpMyAdmin - 错误无法启动会话而没有错误,请检查PHP和/或webserver日志文件中给出的错误并正确配置PHP安装。” 但现在它的工作。可能是那个吗?
<?php
echo "<h1>Register</h1>";
$submit = filter_input(INPUT_POST, 'submit');
//form data
$fullname = strip_tags (filter_input(INPUT_POST, 'fullname'));
$username = strtolower(strip_tags (filter_input(INPUT_POST, 'username')));
$password = strip_tags(filter_input(INPUT_POST, 'password'));
$repeatpassword = strip_tags(filter_input(INPUT_POST, 'repeatpassword'));
$date = date("Y-m-d");
if ($submit)
{
//open database
$connect=mysql_connect("localhost","root","mypasswordwouldgohere");
mysql_select_db("phplogin");
$namecheck = mysql_query("SELECT username FROM users WHERE username='$username'" );
$count = mysql_num_rows($namecheck);
if($count!=0)
{
die("Username already taken, please choose another");
}
//check for existence
if($fullname&&$username&&$password&&$repeatpassword)
{
if ($password==$repeatpassword)
{
//check char length of username and fullname
if (strlen($username)>25||strlen($fullname)>25)
{
echo "Length of username or full name is too long!";
}
else
{
//check password length
if (strlen ($password)>25 || strlen ($password)<6)
{
echo "Password must be between 6 and 25 characters";
}
else
{
$password = md5($password);
//register user
$queryreg = mysql_query("INSERT INTO users VALUES ('','$fullname','$username','$password','$date',)");
die ("You have been registered! <a href='index.php'>Return to the login page</a>");
}
}
}
else echo "Your passwords do not match";
}
else echo "Please fill in <b>all</b> fields!";
}
?>
<p>
<html>
<form action='register.php' method='POST'>
<table>
<tr>
<td>
Your full name:
</td>
<td>
<input type='text' name='fullname' value='<?php echo $fullname;?>'>
</td>
</tr>
<tr>
<td>
choose a username:
</td>
<td>
<input type='text' name='username' value='<?php echo $username;?>'>
</td>
</tr>
<tr>
<td>
Choose a password:
</td>
<td>
<input type='password' name='password'>
</td>
</tr>
<tr>
<td>
Repeat your password:
</td>
<td>
<input type='password' name='repeatpassword'>
</td>
</tr>
<table>
<p>
<input type='submit' name='submit' value='Register'>
</form>
答案 0 :(得分:2)
此处有SQL语法错误"INSERT INTO users VALUES ('','$fullname','$username','$password','$date',)"
。在查询中删除最后一个','。