PHP网站调试
PHP website debug
我有一个问题,
什么时候不能 运行 这个程序,
它显示
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> </td>
<td><input type="submit" name="bttLogin" value="Login"></td>
</tr>
感谢您的回答:)
首先,正确粘贴您的代码...您最后缺少 </table>
和 </form>
...
其次,您在
行中遗漏了一个简单的撇号和一个 semi-colon
$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> </td>
<td><input type="submit" name="bttLogin" value="Login"></td>
</tr>
</table>
</form>
将 mysquli_query
更改为 mysqli_query
,因为它不是有效的扩展名,我认为它的拼写错误。
修改后的查询:
$result = mysqli_query($con, "SELECT * FROM account
WHERE username='" . $username . "'
AND password ='". $password ."'");
另请注意,您错过了同一行的终止符 分号 (;)。
我有一个问题, 什么时候不能 运行 这个程序, 它显示
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> </td>
<td><input type="submit" name="bttLogin" value="Login"></td>
</tr>
感谢您的回答:)
首先,正确粘贴您的代码...您最后缺少 </table>
和 </form>
...
其次,您在
行中遗漏了一个简单的撇号和一个 semi-colon$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> </td>
<td><input type="submit" name="bttLogin" value="Login"></td>
</tr>
</table>
</form>
将 mysquli_query
更改为 mysqli_query
,因为它不是有效的扩展名,我认为它的拼写错误。
修改后的查询:
$result = mysqli_query($con, "SELECT * FROM account
WHERE username='" . $username . "'
AND password ='". $password ."'");
另请注意,您错过了同一行的终止符 分号 (;)。