这基本上是我第一次使用PHP。我正在尝试创建一个预订系统,但我现在已经在注册页面停留了很长一段时间。我最终得到“Parse error:语法错误,第57行的C:\ xampp \ htdocs \ feha \ registration.php中的意外T_STRING”。第57行是:
$register = mysql_query("INSERT INTO 'users' (username, password, fname, lname, address, contact) VALUES ('".$username."','".$password."','".$fname."','".$lname."','".$address."','".$contact."')");
我已尝试在“INSERT ...之前使用反斜杠...并且错误不再出现,但没有其他任何内容,就此而言。如果用户已经注册或者如果有的话,它应该显示一条消息我也试过在值上使用单引号,取出表名上的引号,删除列名。
它暂时修复它,但是然后另一个解析错误出现在我的程序中,我以某种方式修复它,直到它在第62行(我的结束行)显示有关意外$ end的错误。这是我的全部代码:
<?php
include 'connectdb.php';//database connection
if (isset($_POST['register']))
{
//input fields
$register = addslashes(strip_tags($_POST['register']));
$username = addslashes(strip_tags($_POST['username']));
$fname = addslashes(strip_tags($_POST['fname']));
$lname = addslashes(strip_tags($_POST['lname']));
$address = addslashes(strip_tags($_POST['address']));
$contact = addslashes(strip_tags($_POST['contact']));
$email = addslashes(strip_tags($_POST['email']));
$password = strip_tags($_POST['password']);
$repeat = strip_tags($_POST['repeat']);
//check for values
$errors = array();
if ($username&&$fname&&$lname &&$address&& $contact&& $email&&
$password&&$repeat)
{
if ($password!=$repeat) ///check if pw match
{
die("Your password does not match!");
}//check char length of username
if (strlen($username)<6||strlen($username)>32)
{
die ("Username must be between 6 and 32 characters");
}
//checking for password length
if (strlen(strlen($password)<8||$password)>12)
{
die ("Password must be between 8 - 12 characters");
}
//encrypt password
$password = md5($password);
//check if username already taken
$check = mysql_query ("SELECT * FROM users WHERE username='$username'");
if (mysql_num_rows($check)>=1)
{
die ("Username already taken);
}
if (!empty($errors))
{
foreach ($errors as $error)
{
echo $error, '<br/>';
}
}
else
{
$register = mysql_query("INSERT INTO 'users' (username, password, fname, lname, address, contact) VALUES ('".$username."','".$password."','".$fname."','".$lname."','".$address."','".$contact."')");
echo '<div id="good">You have been registered succesfully! ';}
}
else{echo "Please fill in all the fields";}
}
?>
答案 0 :(得分:3)
应该是,
die ("Username already taken");