所以這是事情。我正在嘗試爲部分作業做一個註冊和登錄表單。每當我嘗試在我的服務器上運行它(使用WAMP)時,它總是顯示一個錯誤,說「PHP代碼給我一個錯誤?
解析錯誤:語法錯誤,在C:\ wamp64 \ www \ config.php中出現意外的''root''(T_CONSTANT_ENCAPSED_STRING)第2行
我不知道它會導致我的數據庫建立正確的什麼是錯的。有人可以請幫助我。這裏的PHP腳本
register.php
<?php
require('config.php');
if (isset($_POST['submit']))
{
$email1 = $_POST['email1'];
$email2 = $_POST['email2'];
$pass1 = $_POST['pass1'];
$pass2 = $_POST['pass2'];
if($email1 == $email2 && $pass1 == $pass2)
{
//All good
$name = mysql_escape_string($_POST['name']);
$lname = mysql_escape_string($_POST['lname']);
$uname = mysql_escape_string($_POST['uname']);
$email1 = mysql_escape_string($_POST['email1']);
$email2 = mysql_escape_string($_POST['email2']);
$pass1 = mysql_escape_string($_POST['pass1']);
$pass2 = mysql_escape_string($_POST['pass2']);
$pass1 = md5($pass1);
//Check if username is taken
$check = mysql_query("SELECT * FROM users WHERE uname = '$uname'")or die(mysql_error());
if (mysql_num_rows($check)>=1) echo "Username already taken";
//Put everyting in DB
else{
mysql_query("INSERT INTO `users` (`id`, `name`, `lname`, `uname`, `email`, `pass`) VALUES (NULL, '$name', '$lname', '$uname', '$email1', '$pass1')") or die(mysql_error());
echo "Registration Successful";
}
}
else{
echo "Sorry, your email's or your passwords do not match. <br />";
}
}
else{
$form = <<<EOT
<form action="register.php" method="POST">
First Name: <input type="text" name="name" /><br />
Last Name: <input type="text" name="lname" /><br />
Username: <input type="text" name="uname" /><br />
Email: <input type="text" name="email1" /><br />
Confirm Email: <input type="text" name="email2" /><br />
Password: <input type="password" name="pass1" /><br />
Confirm Password: <input type="password" name="pass2" /><br />
<input type="submit" value="Register" name="submit" />
</form>
EOT;
echo $form;
}
?>
登錄。 php
<?php
require('config.php');
if(isset($_POST['submit']))
{
$uname = mysql_escape_string($_POST['uname']);
$pass = mysql_escape_string($_POST['pass']);
$pass = md5($pass);
$check = mysql_query("SELECT * FROM `users` WHERE `uname` = '$uname' AND `pass` = '$pass'");
if(mysql_num_rows($check) >= 1){
echo "You are now logged in!";
exit();
}
else{
echo "Wrong password";
}
}
else{
$form = <<<EOT
<form action="login.php" method="POST">
Username: <input type="text" name="uname"><br>
Password: <input type="password" name="pass"><br>
<input type="submit" name="submit" value="Log in">
EOT;
echo $form;
}
?>
的config.php
<?php
mysqli_connect('localhost' 'root' '');
mysql_select_db('register');
?>
即使錯誤所在的位置被PHP明確告訴了您,您也必須發佈所有*代碼。 –
下面是你應該熟悉的另一個問題和答案:[我可以在PHP中混合MySQL API嗎?](http://stackoverflow.com/q/17498216/354577)(你不能。) – Chris
你不是想要和這個一起生活,*你是嗎?* –