2017-03-20 125 views
-2

所以這是事情。我正在嘗試爲部分作業做一個註冊和登錄表單。每當我嘗試在我的服務器上運行它(使用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'); 

?> 
+1

即使錯誤所在的位置被PHP明確告訴了您,您也必須發佈所有*代碼。 –

+0

下面是你應該熟悉的另一個問題和答案:[我可以在PHP中混合MySQL API嗎?](http://stackoverflow.com/q/17498216/354577)(你不能。) – Chris

+0

你不是想要和這個一起生活,*你是嗎?* –

回答

-1

在配置文件中添加逗號對每個paramaeter。

mysqli_connect('localhost', 'root', ''); 
+0

請不要在明顯的題外話題上發表回答! [請參閱:**是否應該提出關於主題問題的建議?**](http://meta.stackoverflow.com/q/276572/1768232)可以關閉和刪除離題問題,這可能會使您的貢獻無效。 –

+1

不是我在這裏downvote,但你遺漏了一些東西,但他們的代碼的其餘部分是mysql_。除非您在mysqli_中完全重寫了他們的代碼,否則您發佈的內容將無法使用。 –

+0

充其量,應該讀爲'mysql_connect('localhost','root','');' –