我有一个问题, 什么时候不能运行这个程序, 它显示
解析错误:语法错误,意外的'用户名'(T_STRING) 第9行的C:\ xampp \ htdocs \ fypp \ index.php
<?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>
感谢您的回答:)
答案 0 :(得分:0)
首先,正确粘贴代码......最后您遗漏了</table>
和</form>
...
其次,你错过了一行中的简单撇号和分号
$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>
答案 1 :(得分:0)
将mysquli_query
更改为mysqli_query
,因为它不是有效的扩展程序,而且我认为它的拼写错误。
修改后的查询:
$result = mysqli_query($con, "SELECT * FROM account
WHERE username='" . $username . "'
AND password ='". $password ."'");
另请注意,您错过了同一行的半冒号(;)终止。