2016-01-26 110 views
-6

我有一個問題,當 無法運行此程序, 它顯示PHP網站調試

Parse error: syntax error, unexpected 'username' (T_STRING) in C:\xampp\htdocs\fypp\index.php on line 9

<?php 
    session_start(); 
    if (isset($_POST['bttLogin'])){ 
     require 'connect.php'; 
     $username = $_POST['username']; 
     $password = $_POST['password']; 
     $result = mysquli_query($con, 'select * from account where username="'.$username.'" and password="'.$password.'") 
     if(mysqli_num_rows($result)==1) { 
      $_SESSION['username'] = $username; 
      header("Location: welcome.php"); 
     } 
     else 
      echo "account is invalid"; 
    } 
    ?> 
    <form method="post"> 
    <table cellpadding="2" cellspacing="2" border="1"> 
     <tr> 
      <td>Username</td> 
      <td><input type="text" name="username"></td> 
     </tr> 
     <tr> 
      <td>Password</td> 
      <td><input type="password"" name="password"></td> 
     </tr> 
     <tr> 
      <td>&nbsp;</td> 
      <td><input type="submit" name="bttLogin" value="Login"></td> 
     </tr> 

謝謝回答:)

+3

SO的語法高亮已經顯示出來 – Ghost

+0

我應該如何更正它:X謝謝 – xrina

+0

'mysquli_query'沒有'mysquli'庫,有'mysql'。首先進行一些常規調試。 – Ohgodwhy

回答

0

首先,正確粘貼代碼.. 。您最後缺少</table></form> ...

其次,您錯過了一個簡單的撇號和一個半色調n的行

$result = mysquli_query($con, 'select * from account where username="'.$username.'" and password="'.$password.'")

此外,你應該使用mysqli_query代替mysqlui_query ...錯字!

你的代碼應該如下:

<?php 
session_start(); 
if (isset($_POST['bttLogin'])){ 
    require 'connect.php'; 
    $username = $_POST['username']; 
    $password = $_POST['password']; 
    $result = mysqli_query($con, 'select * from account where username="'.$username.'" and password="'.$password.'"'); 
    if(mysqli_num_rows($result)==1) { 
     $_SESSION['username'] = $username; 
     header("Location: welcome.php"); 
    } 
    else 
     echo "account is invalid"; 
} 
?> 

<form method="post"> 
<table cellpadding="2" cellspacing="2" border="1"> 
    <tr> 
     <td>Username</td> 
     <td><input type="text" name="username"></td> 
    </tr> 
    <tr> 
     <td>Password</td> 
     <td><input type="password"" name="password"></td> 
    </tr> 
    <tr> 
     <td>&nbsp;</td> 
     <td><input type="submit" name="bttLogin" value="Login"></td> 
    </tr> 
</table> 
</form> 
+1

'mysquli_query'。這就是爲什麼這些類型的問題對於SO來說是一個糟糕的經歷。今後很可能不會幫助任何人,只是獲得Karma並幫助任何人的手段,包括OP。 – Ohgodwhy

+0

@Ohgodwhy我在我的答案中也解決了這個問題...沒有提到它...會做... – prateekkathal

+0

@xrina如果它解決了您的問題,請選擇它作爲答案...:| | – prateekkathal

0

變化mysquli_querymysqli_query,因爲它不是一個有效的擴展,我認爲它的錯字錯誤。

修改的查詢:

$result = mysqli_query($con, "SELECT * FROM account 
          WHERE username='" . $username . "' 
          AND password ='". $password ."'"); 

還要注意的是,你錯過了終止分號(;)在同一行

+0

RU更新你的答案???? – devpro

+0

我修改了你的答案。 – devpro

+0

你的代碼在語法錯誤,這個真正的連接:) –