MySQL数据库信息未出现在PHP页面上
我遇到了一个奇怪的问题。我正在为MySQL数据库开发一个web界面,并尝试使用PHP从中获取信息。简言之,当我不与其他人在一起时,我能够从一些数据库中很好地检索信息MySQL数据库信息未出现在PHP页面上,php,mysql,Php,Mysql,我遇到了一个奇怪的问题。我正在为MySQL数据库开发一个web界面,并尝试使用PHP从中获取信息。简言之,当我不与其他人在一起时,我能够从一些数据库中很好地检索信息 $userList = mysql_query("SELECT * FROM myTable"); while ($userInfo = mysql_fetch_array($userList) ) { echo "<p>Name = " . $userInfo["name"] . ". Password = "
$userList = mysql_query("SELECT * FROM myTable");
while ($userInfo = mysql_fetch_array($userList) )
{
echo "<p>Name = " . $userInfo["name"] . ". Password = " . $userInfo["password"] . ".</p>";
}
<head>
<title>My Web Interface</title>
</head>
<?php
if (!($_POST["go"]))
{
?><h1>Hello World!</h1>
<form action="test.php" method="post">
Username: <input type="text" name="username" /> <br />
Password: <input type="text" name="password" /> <br />
<input type="submit" name="go" />
</form>
<?php
}
else //the user has submitted: in which case, we check if the details match any user info in the database
{
$username = $_POST["username"];
$password = $_POST["password"];
//the database info variables
$hostname = "myhostname";
$dbUsername = "myusername";
$dbPassword = "mypassword";
echo "<p>You entered the username and password combo of '$username' and '$password'.</p>";
$connect = mysql_connect($hostname, $dbUsername, $dbPassword) or die ("Unable to connect to MySQL");
//test for the connection's presence. Every time so far it's returned True.
if ($connect)
{
echo "Got it!";
}
else
{
echo "Don't got it!";
}
//echo "<p>My username is " . $dbUsername ", my hostname is " . $hostname . " and my password is " . $dbPassword . ".</p>";
$selected = mysql_select_db("myDatabase",$connect)
or die("Could not select examples");
$userList = mysql_query("SELECT * FROM testUsers;");
/****
* This part tests to show a connection between the user and the database.
* It should return a list of users and the rights they have.
***
*/
$found = false; //how we terminate the loop.
//echo "<ul>";
while ($userInfo = mysql_fetch_array($userList) )
{
echo "<p>Name = " . $userInfo["name"] . ". Password = " . $userInfo["password"] . ".</p>";
if ($userInfo["password"] == $password)
{
echo "<p>The passwords match and are both $password!</p>";
}
else
{
echo "<p>$password does not match with " . $userInfo["password"] . "!</p>";
}
}
while ( ($userInfo = mysql_fetch_array($userList) ) && (!($found)) )
{
echo "The current username is " . $userInfo["name"] . ". <ul>";
if ($username == $userInfo["name"])
{
$found = true;
echo "<p>We found you in the database, " . $userInfo['name'] . ". Now to test your password.</p>";
if ($password == $userInfo['password'])
{
echo "<p>The password you entered, " . $userInfo['password'] . " was correct!</p>";
//now show the table's contents
$register = mysql_query("SELECT * FROM myTable;");
while ($col = mysql_fetch_array($register) )
{
echo "<li>Tag: " . $col['service_tag'] . "</li>";
}
}
else //the username is right but the password is wrong.
{
echo "The password didn't match, though!";
}
}
else //this username isn't the right one.
{
echo "<p>$username does not match " . $userInfo['name'] . ".";
}
echo "</ul>";
}
/*
*Test code: trying to output the testUsers info without the conditions.
*/
if (!$found)
{
echo "<p>We could not find you in the database. Did you enter your username correctly?</p>";
}
echo "</ul>";
mysql_close($connect);
}
?>
$userList=mysql\u查询(“从myTable中选择*);
而($userInfo=mysql\u fetch\u数组($userList))
{
echo“Name=“.$userInfo[“Name”]”。Password=“.$userInfo[“Password”]”。”;
<head>
<title>My Web Interface</title>
</head>
<?php
if (!($_POST["go"]))
{
?><h1>Hello World!</h1>
<form action="test.php" method="post">
Username: <input type="text" name="username" /> <br />
Password: <input type="text" name="password" /> <br />
<input type="submit" name="go" />
</form>
<?php
}
else //the user has submitted: in which case, we check if the details match any user info in the database
{
$username = $_POST["username"];
$password = $_POST["password"];
//the database info variables
$hostname = "myhostname";
$dbUsername = "myusername";
$dbPassword = "mypassword";
echo "<p>You entered the username and password combo of '$username' and '$password'.</p>";
$connect = mysql_connect($hostname, $dbUsername, $dbPassword) or die ("Unable to connect to MySQL");
//test for the connection's presence. Every time so far it's returned True.
if ($connect)
{
echo "Got it!";
}
else
{
echo "Don't got it!";
}
//echo "<p>My username is " . $dbUsername ", my hostname is " . $hostname . " and my password is " . $dbPassword . ".</p>";
$selected = mysql_select_db("myDatabase",$connect)
or die("Could not select examples");
$userList = mysql_query("SELECT * FROM testUsers;");
/****
* This part tests to show a connection between the user and the database.
* It should return a list of users and the rights they have.
***
*/
$found = false; //how we terminate the loop.
//echo "<ul>";
while ($userInfo = mysql_fetch_array($userList) )
{
echo "<p>Name = " . $userInfo["name"] . ". Password = " . $userInfo["password"] . ".</p>";
if ($userInfo["password"] == $password)
{
echo "<p>The passwords match and are both $password!</p>";
}
else
{
echo "<p>$password does not match with " . $userInfo["password"] . "!</p>";
}
}
while ( ($userInfo = mysql_fetch_array($userList) ) && (!($found)) )
{
echo "The current username is " . $userInfo["name"] . ". <ul>";
if ($username == $userInfo["name"])
{
$found = true;
echo "<p>We found you in the database, " . $userInfo['name'] . ". Now to test your password.</p>";
if ($password == $userInfo['password'])
{
echo "<p>The password you entered, " . $userInfo['password'] . " was correct!</p>";
//now show the table's contents
$register = mysql_query("SELECT * FROM myTable;");
while ($col = mysql_fetch_array($register) )
{
echo "<li>Tag: " . $col['service_tag'] . "</li>";
}
}
else //the username is right but the password is wrong.
{
echo "The password didn't match, though!";
}
}
else //this username isn't the right one.
{
echo "<p>$username does not match " . $userInfo['name'] . ".";
}
echo "</ul>";
}
/*
*Test code: trying to output the testUsers info without the conditions.
*/
if (!$found)
{
echo "<p>We could not find you in the database. Did you enter your username correctly?</p>";
}
echo "</ul>";
mysql_close($connect);
}
?>
}
这部分只是一个测试,效果很好。我得到数据库中每个人的名字和密码。但当我尝试这样做时,我会遇到错误。认为
while ( ($userInfo = mysql_fetch_array($userList) ) && (!$found) )
{
echo "The current username is " . $userInfo["name"] . ". <ul>";
if ($username == $userInfo["name"])
{
$found = true;
if ($password == $userInfo['password'])
{
echo "The password you entered, " . $userInfo['password'] . " was correct!";
//things which we do once the account is confirmed
}
else //the username is right but the password is wrong.
{
"The password didn't match, though!";
}
}
else //this username isn't the right one.
{
echo "<p>$username does not match " . $userInfo['name'] . ".";
}
echo "</ul>";
}
<head>
<title>My Web Interface</title>
</head>
<?php
if (!($_POST["go"]))
{
?><h1>Hello World!</h1>
<form action="test.php" method="post">
Username: <input type="text" name="username" /> <br />
Password: <input type="text" name="password" /> <br />
<input type="submit" name="go" />
</form>
<?php
}
else //the user has submitted: in which case, we check if the details match any user info in the database
{
$username = $_POST["username"];
$password = $_POST["password"];
//the database info variables
$hostname = "myhostname";
$dbUsername = "myusername";
$dbPassword = "mypassword";
echo "<p>You entered the username and password combo of '$username' and '$password'.</p>";
$connect = mysql_connect($hostname, $dbUsername, $dbPassword) or die ("Unable to connect to MySQL");
//test for the connection's presence. Every time so far it's returned True.
if ($connect)
{
echo "Got it!";
}
else
{
echo "Don't got it!";
}
//echo "<p>My username is " . $dbUsername ", my hostname is " . $hostname . " and my password is " . $dbPassword . ".</p>";
$selected = mysql_select_db("myDatabase",$connect)
or die("Could not select examples");
$userList = mysql_query("SELECT * FROM testUsers;");
/****
* This part tests to show a connection between the user and the database.
* It should return a list of users and the rights they have.
***
*/
$found = false; //how we terminate the loop.
//echo "<ul>";
while ($userInfo = mysql_fetch_array($userList) )
{
echo "<p>Name = " . $userInfo["name"] . ". Password = " . $userInfo["password"] . ".</p>";
if ($userInfo["password"] == $password)
{
echo "<p>The passwords match and are both $password!</p>";
}
else
{
echo "<p>$password does not match with " . $userInfo["password"] . "!</p>";
}
}
while ( ($userInfo = mysql_fetch_array($userList) ) && (!($found)) )
{
echo "The current username is " . $userInfo["name"] . ". <ul>";
if ($username == $userInfo["name"])
{
$found = true;
echo "<p>We found you in the database, " . $userInfo['name'] . ". Now to test your password.</p>";
if ($password == $userInfo['password'])
{
echo "<p>The password you entered, " . $userInfo['password'] . " was correct!</p>";
//now show the table's contents
$register = mysql_query("SELECT * FROM myTable;");
while ($col = mysql_fetch_array($register) )
{
echo "<li>Tag: " . $col['service_tag'] . "</li>";
}
}
else //the username is right but the password is wrong.
{
echo "The password didn't match, though!";
}
}
else //this username isn't the right one.
{
echo "<p>$username does not match " . $userInfo['name'] . ".";
}
echo "</ul>";
}
/*
*Test code: trying to output the testUsers info without the conditions.
*/
if (!$found)
{
echo "<p>We could not find you in the database. Did you enter your username correctly?</p>";
}
echo "</ul>";
mysql_close($connect);
}
?>
while($userInfo=mysql\u fetch\u array($userList))&&(!$found))
{
echo“当前用户名为”。$userInfo[“name”]。”;
如果($username==$userInfo[“name”])
{
$found=true;
如果($password==$userInfo['password']))
{
echo“您输入的密码,.$userInfo['password']”正确;
//账户确认后我们所做的事情
}
否则//用户名是正确的,但密码是错误的。
{
“但是密码不匹配!”;
}
}
否则//此用户名不正确。
{
echo“$username与“$userInfo['name']”不匹配;
}
回声“
”;
}
具体来说,$userInfo[“name”]和$userInfo[“password”]字符在第二个代码块中完全不返回任何内容,而在第一个代码块中,它们似乎工作正常。我不明白为什么两者之间有区别
<head>
<title>My Web Interface</title>
</head>
<?php
if (!($_POST["go"]))
{
?><h1>Hello World!</h1>
<form action="test.php" method="post">
Username: <input type="text" name="username" /> <br />
Password: <input type="text" name="password" /> <br />
<input type="submit" name="go" />
</form>
<?php
}
else //the user has submitted: in which case, we check if the details match any user info in the database
{
$username = $_POST["username"];
$password = $_POST["password"];
//the database info variables
$hostname = "myhostname";
$dbUsername = "myusername";
$dbPassword = "mypassword";
echo "<p>You entered the username and password combo of '$username' and '$password'.</p>";
$connect = mysql_connect($hostname, $dbUsername, $dbPassword) or die ("Unable to connect to MySQL");
//test for the connection's presence. Every time so far it's returned True.
if ($connect)
{
echo "Got it!";
}
else
{
echo "Don't got it!";
}
//echo "<p>My username is " . $dbUsername ", my hostname is " . $hostname . " and my password is " . $dbPassword . ".</p>";
$selected = mysql_select_db("myDatabase",$connect)
or die("Could not select examples");
$userList = mysql_query("SELECT * FROM testUsers;");
/****
* This part tests to show a connection between the user and the database.
* It should return a list of users and the rights they have.
***
*/
$found = false; //how we terminate the loop.
//echo "<ul>";
while ($userInfo = mysql_fetch_array($userList) )
{
echo "<p>Name = " . $userInfo["name"] . ". Password = " . $userInfo["password"] . ".</p>";
if ($userInfo["password"] == $password)
{
echo "<p>The passwords match and are both $password!</p>";
}
else
{
echo "<p>$password does not match with " . $userInfo["password"] . "!</p>";
}
}
while ( ($userInfo = mysql_fetch_array($userList) ) && (!($found)) )
{
echo "The current username is " . $userInfo["name"] . ". <ul>";
if ($username == $userInfo["name"])
{
$found = true;
echo "<p>We found you in the database, " . $userInfo['name'] . ". Now to test your password.</p>";
if ($password == $userInfo['password'])
{
echo "<p>The password you entered, " . $userInfo['password'] . " was correct!</p>";
//now show the table's contents
$register = mysql_query("SELECT * FROM myTable;");
while ($col = mysql_fetch_array($register) )
{
echo "<li>Tag: " . $col['service_tag'] . "</li>";
}
}
else //the username is right but the password is wrong.
{
echo "The password didn't match, though!";
}
}
else //this username isn't the right one.
{
echo "<p>$username does not match " . $userInfo['name'] . ".";
}
echo "</ul>";
}
/*
*Test code: trying to output the testUsers info without the conditions.
*/
if (!$found)
{
echo "<p>We could not find you in the database. Did you enter your username correctly?</p>";
}
echo "</ul>";
mysql_close($connect);
}
?>
如果我能得到任何帮助或建议,我将不胜感激
<head>
<title>My Web Interface</title>
</head>
<?php
if (!($_POST["go"]))
{
?><h1>Hello World!</h1>
<form action="test.php" method="post">
Username: <input type="text" name="username" /> <br />
Password: <input type="text" name="password" /> <br />
<input type="submit" name="go" />
</form>
<?php
}
else //the user has submitted: in which case, we check if the details match any user info in the database
{
$username = $_POST["username"];
$password = $_POST["password"];
//the database info variables
$hostname = "myhostname";
$dbUsername = "myusername";
$dbPassword = "mypassword";
echo "<p>You entered the username and password combo of '$username' and '$password'.</p>";
$connect = mysql_connect($hostname, $dbUsername, $dbPassword) or die ("Unable to connect to MySQL");
//test for the connection's presence. Every time so far it's returned True.
if ($connect)
{
echo "Got it!";
}
else
{
echo "Don't got it!";
}
//echo "<p>My username is " . $dbUsername ", my hostname is " . $hostname . " and my password is " . $dbPassword . ".</p>";
$selected = mysql_select_db("myDatabase",$connect)
or die("Could not select examples");
$userList = mysql_query("SELECT * FROM testUsers;");
/****
* This part tests to show a connection between the user and the database.
* It should return a list of users and the rights they have.
***
*/
$found = false; //how we terminate the loop.
//echo "<ul>";
while ($userInfo = mysql_fetch_array($userList) )
{
echo "<p>Name = " . $userInfo["name"] . ". Password = " . $userInfo["password"] . ".</p>";
if ($userInfo["password"] == $password)
{
echo "<p>The passwords match and are both $password!</p>";
}
else
{
echo "<p>$password does not match with " . $userInfo["password"] . "!</p>";
}
}
while ( ($userInfo = mysql_fetch_array($userList) ) && (!($found)) )
{
echo "The current username is " . $userInfo["name"] . ". <ul>";
if ($username == $userInfo["name"])
{
$found = true;
echo "<p>We found you in the database, " . $userInfo['name'] . ". Now to test your password.</p>";
if ($password == $userInfo['password'])
{
echo "<p>The password you entered, " . $userInfo['password'] . " was correct!</p>";
//now show the table's contents
$register = mysql_query("SELECT * FROM myTable;");
while ($col = mysql_fetch_array($register) )
{
echo "<li>Tag: " . $col['service_tag'] . "</li>";
}
}
else //the username is right but the password is wrong.
{
echo "The password didn't match, though!";
}
}
else //this username isn't the right one.
{
echo "<p>$username does not match " . $userInfo['name'] . ".";
}
echo "</ul>";
}
/*
*Test code: trying to output the testUsers info without the conditions.
*/
if (!$found)
{
echo "<p>We could not find you in the database. Did you enter your username correctly?</p>";
}
echo "</ul>";
mysql_close($connect);
}
?>
编辑:对于那些想要完整代码的人,这里就是。
<head>
<title>My Web Interface</title>
</head>
<?php
if (!($_POST["go"]))
{
?><h1>Hello World!</h1>
<form action="test.php" method="post">
Username: <input type="text" name="username" /> <br />
Password: <input type="text" name="password" /> <br />
<input type="submit" name="go" />
</form>
<?php
}
else //the user has submitted: in which case, we check if the details match any user info in the database
{
$username = $_POST["username"];
$password = $_POST["password"];
//the database info variables
$hostname = "myhostname";
$dbUsername = "myusername";
$dbPassword = "mypassword";
echo "<p>You entered the username and password combo of '$username' and '$password'.</p>";
$connect = mysql_connect($hostname, $dbUsername, $dbPassword) or die ("Unable to connect to MySQL");
//test for the connection's presence. Every time so far it's returned True.
if ($connect)
{
echo "Got it!";
}
else
{
echo "Don't got it!";
}
//echo "<p>My username is " . $dbUsername ", my hostname is " . $hostname . " and my password is " . $dbPassword . ".</p>";
$selected = mysql_select_db("myDatabase",$connect)
or die("Could not select examples");
$userList = mysql_query("SELECT * FROM testUsers;");
/****
* This part tests to show a connection between the user and the database.
* It should return a list of users and the rights they have.
***
*/
$found = false; //how we terminate the loop.
//echo "<ul>";
while ($userInfo = mysql_fetch_array($userList) )
{
echo "<p>Name = " . $userInfo["name"] . ". Password = " . $userInfo["password"] . ".</p>";
if ($userInfo["password"] == $password)
{
echo "<p>The passwords match and are both $password!</p>";
}
else
{
echo "<p>$password does not match with " . $userInfo["password"] . "!</p>";
}
}
while ( ($userInfo = mysql_fetch_array($userList) ) && (!($found)) )
{
echo "The current username is " . $userInfo["name"] . ". <ul>";
if ($username == $userInfo["name"])
{
$found = true;
echo "<p>We found you in the database, " . $userInfo['name'] . ". Now to test your password.</p>";
if ($password == $userInfo['password'])
{
echo "<p>The password you entered, " . $userInfo['password'] . " was correct!</p>";
//now show the table's contents
$register = mysql_query("SELECT * FROM myTable;");
while ($col = mysql_fetch_array($register) )
{
echo "<li>Tag: " . $col['service_tag'] . "</li>";
}
}
else //the username is right but the password is wrong.
{
echo "The password didn't match, though!";
}
}
else //this username isn't the right one.
{
echo "<p>$username does not match " . $userInfo['name'] . ".";
}
echo "</ul>";
}
/*
*Test code: trying to output the testUsers info without the conditions.
*/
if (!$found)
{
echo "<p>We could not find you in the database. Did you enter your username correctly?</p>";
}
echo "</ul>";
mysql_close($connect);
}
?>
我的Web界面
你好,世界!
用户名:
密码:
我想你给我们看的不是完整的代码。您必须在某个地方为数据库设置凭据,这是在您将值设置为$username之前还是之后?也许您也在数据库连接中使用了$username?我认为您没有向我们展示完整的代码。您必须在某个地方为数据库设置凭据,这是在您将值设置为$username之前还是之后?也许您也在数据库连接中使用了$username?这是因为(!($found)
在您的while循环中。该循环的最终状态必须为true,循环才能采取行动,但它始终为false,因为您要求它不是false,而是false。因此,它将不起作用,因为不满足条件。
<head>
<title>My Web Interface</title>
</head>
<?php
if (!($_POST["go"]))
{
?><h1>Hello World!</h1>
<form action="test.php" method="post">
Username: <input type="text" name="username" /> <br />
Password: <input type="text" name="password" /> <br />
<input type="submit" name="go" />
</form>
<?php
}
else //the user has submitted: in which case, we check if the details match any user info in the database
{
$username = $_POST["username"];
$password = $_POST["password"];
//the database info variables
$hostname = "myhostname";
$dbUsername = "myusername";
$dbPassword = "mypassword";
echo "<p>You entered the username and password combo of '$username' and '$password'.</p>";
$connect = mysql_connect($hostname, $dbUsername, $dbPassword) or die ("Unable to connect to MySQL");
//test for the connection's presence. Every time so far it's returned True.
if ($connect)
{
echo "Got it!";
}
else
{
echo "Don't got it!";
}
//echo "<p>My username is " . $dbUsername ", my hostname is " . $hostname . " and my password is " . $dbPassword . ".</p>";
$selected = mysql_select_db("myDatabase",$connect)
or die("Could not select examples");
$userList = mysql_query("SELECT * FROM testUsers;");
/****
* This part tests to show a connection between the user and the database.
* It should return a list of users and the rights they have.
***
*/
$found = false; //how we terminate the loop.
//echo "<ul>";
while ($userInfo = mysql_fetch_array($userList) )
{
echo "<p>Name = " . $userInfo["name"] . ". Password = " . $userInfo["password"] . ".</p>";
if ($userInfo["password"] == $password)
{
echo "<p>The passwords match and are both $password!</p>";
}
else
{
echo "<p>$password does not match with " . $userInfo["password"] . "!</p>";
}
}
while ( ($userInfo = mysql_fetch_array($userList) ) && (!($found)) )
{
echo "The current username is " . $userInfo["name"] . ". <ul>";
if ($username == $userInfo["name"])
{
$found = true;
echo "<p>We found you in the database, " . $userInfo['name'] . ". Now to test your password.</p>";
if ($password == $userInfo['password'])
{
echo "<p>The password you entered, " . $userInfo['password'] . " was correct!</p>";
//now show the table's contents
$register = mysql_query("SELECT * FROM myTable;");
while ($col = mysql_fetch_array($register) )
{
echo "<li>Tag: " . $col['service_tag'] . "</li>";
}
}
else //the username is right but the password is wrong.
{
echo "The password didn't match, though!";
}
}
else //this username isn't the right one.
{
echo "<p>$username does not match " . $userInfo['name'] . ".";
}
echo "</ul>";
}
/*
*Test code: trying to output the testUsers info without the conditions.
*/
if (!$found)
{
echo "<p>We could not find you in the database. Did you enter your username correctly?</p>";
}
echo "</ul>";
mysql_close($connect);
}
?>
请尝试从中删除!
,并对其进行测试。如果无法以这种方式执行,请尝试使用以下方法:
<head>
<title>My Web Interface</title>
</head>
<?php
if (!($_POST["go"]))
{
?><h1>Hello World!</h1>
<form action="test.php" method="post">
Username: <input type="text" name="username" /> <br />
Password: <input type="text" name="password" /> <br />
<input type="submit" name="go" />
</form>
<?php
}
else //the user has submitted: in which case, we check if the details match any user info in the database
{
$username = $_POST["username"];
$password = $_POST["password"];
//the database info variables
$hostname = "myhostname";
$dbUsername = "myusername";
$dbPassword = "mypassword";
echo "<p>You entered the username and password combo of '$username' and '$password'.</p>";
$connect = mysql_connect($hostname, $dbUsername, $dbPassword) or die ("Unable to connect to MySQL");
//test for the connection's presence. Every time so far it's returned True.
if ($connect)
{
echo "Got it!";
}
else
{
echo "Don't got it!";
}
//echo "<p>My username is " . $dbUsername ", my hostname is " . $hostname . " and my password is " . $dbPassword . ".</p>";
$selected = mysql_select_db("myDatabase",$connect)
or die("Could not select examples");
$userList = mysql_query("SELECT * FROM testUsers;");
/****
* This part tests to show a connection between the user and the database.
* It should return a list of users and the rights they have.
***
*/
$found = false; //how we terminate the loop.
//echo "<ul>";
while ($userInfo = mysql_fetch_array($userList) )
{
echo "<p>Name = " . $userInfo["name"] . ". Password = " . $userInfo["password"] . ".</p>";
if ($userInfo["password"] == $password)
{
echo "<p>The passwords match and are both $password!</p>";
}
else
{
echo "<p>$password does not match with " . $userInfo["password"] . "!</p>";
}
}
while ( ($userInfo = mysql_fetch_array($userList) ) && (!($found)) )
{
echo "The current username is " . $userInfo["name"] . ". <ul>";
if ($username == $userInfo["name"])
{
$found = true;
echo "<p>We found you in the database, " . $userInfo['name'] . ". Now to test your password.</p>";
if ($password == $userInfo['password'])
{
echo "<p>The password you entered, " . $userInfo['password'] . " was correct!</p>";
//now show the table's contents
$register = mysql_query("SELECT * FROM myTable;");
while ($col = mysql_fetch_array($register) )
{
echo "<li>Tag: " . $col['service_tag'] . "</li>";
}
}
else //the username is right but the password is wrong.
{
echo "The password didn't match, though!";
}
}
else //this username isn't the right one.
{
echo "<p>$username does not match " . $userInfo['name'] . ".";
}
echo "</ul>";
}
/*
*Test code: trying to output the testUsers info without the conditions.
*/
if (!$found)
{
echo "<p>We could not find you in the database. Did you enter your username correctly?</p>";
}
echo "</ul>";
mysql_close($connect);
}
?>
do {
//your code here to motion
}
while()// your conditions
在这种情况下,只要中的状态为true,而中的状态为true,do
将继续工作。这是因为(!($found)
在您的while循环中。该循环的最终状态必须为true,循环才能采取行动,但它始终为false,因为您要求它不是false,而是false。因此,它将不起作用,因为不满足条件。
<head>
<title>My Web Interface</title>
</head>
<?php
if (!($_POST["go"]))
{
?><h1>Hello World!</h1>
<form action="test.php" method="post">
Username: <input type="text" name="username" /> <br />
Password: <input type="text" name="password" /> <br />
<input type="submit" name="go" />
</form>
<?php
}
else //the user has submitted: in which case, we check if the details match any user info in the database
{
$username = $_POST["username"];
$password = $_POST["password"];
//the database info variables
$hostname = "myhostname";
$dbUsername = "myusername";
$dbPassword = "mypassword";
echo "<p>You entered the username and password combo of '$username' and '$password'.</p>";
$connect = mysql_connect($hostname, $dbUsername, $dbPassword) or die ("Unable to connect to MySQL");
//test for the connection's presence. Every time so far it's returned True.
if ($connect)
{
echo "Got it!";
}
else
{
echo "Don't got it!";
}
//echo "<p>My username is " . $dbUsername ", my hostname is " . $hostname . " and my password is " . $dbPassword . ".</p>";
$selected = mysql_select_db("myDatabase",$connect)
or die("Could not select examples");
$userList = mysql_query("SELECT * FROM testUsers;");
/****
* This part tests to show a connection between the user and the database.
* It should return a list of users and the rights they have.
***
*/
$found = false; //how we terminate the loop.
//echo "<ul>";
while ($userInfo = mysql_fetch_array($userList) )
{
echo "<p>Name = " . $userInfo["name"] . ". Password = " . $userInfo["password"] . ".</p>";
if ($userInfo["password"] == $password)
{
echo "<p>The passwords match and are both $password!</p>";
}
else
{
echo "<p>$password does not match with " . $userInfo["password"] . "!</p>";
}
}
while ( ($userInfo = mysql_fetch_array($userList) ) && (!($found)) )
{
echo "The current username is " . $userInfo["name"] . ". <ul>";
if ($username == $userInfo["name"])
{
$found = true;
echo "<p>We found you in the database, " . $userInfo['name'] . ". Now to test your password.</p>";
if ($password == $userInfo['password'])
{
echo "<p>The password you entered, " . $userInfo['password'] . " was correct!</p>";
//now show the table's contents
$register = mysql_query("SELECT * FROM myTable;");
while ($col = mysql_fetch_array($register) )
{
echo "<li>Tag: " . $col['service_tag'] . "</li>";
}
}
else //the username is right but the password is wrong.
{
echo "The password didn't match, though!";
}
}
else //this username isn't the right one.
{
echo "<p>$username does not match " . $userInfo['name'] . ".";
}
echo "</ul>";
}
/*
*Test code: trying to output the testUsers info without the conditions.
*/
if (!$found)
{
echo "<p>We could not find you in the database. Did you enter your username correctly?</p>";
}
echo "</ul>";
mysql_close($connect);
}
?>
请尝试从中删除!
,并对其进行测试。如果无法以这种方式执行,请尝试使用以下方法:
<head>
<title>My Web Interface</title>
</head>
<?php
if (!($_POST["go"]))
{
?><h1>Hello World!</h1>
<form action="test.php" method="post">
Username: <input type="text" name="username" /> <br />
Password: <input type="text" name="password" /> <br />
<input type="submit" name="go" />
</form>
<?php
}
else //the user has submitted: in which case, we check if the details match any user info in the database
{
$username = $_POST["username"];
$password = $_POST["password"];
//the database info variables
$hostname = "myhostname";
$dbUsername = "myusername";
$dbPassword = "mypassword";
echo "<p>You entered the username and password combo of '$username' and '$password'.</p>";
$connect = mysql_connect($hostname, $dbUsername, $dbPassword) or die ("Unable to connect to MySQL");
//test for the connection's presence. Every time so far it's returned True.
if ($connect)
{
echo "Got it!";
}
else
{
echo "Don't got it!";
}
//echo "<p>My username is " . $dbUsername ", my hostname is " . $hostname . " and my password is " . $dbPassword . ".</p>";
$selected = mysql_select_db("myDatabase",$connect)
or die("Could not select examples");
$userList = mysql_query("SELECT * FROM testUsers;");
/****
* This part tests to show a connection between the user and the database.
* It should return a list of users and the rights they have.
***
*/
$found = false; //how we terminate the loop.
//echo "<ul>";
while ($userInfo = mysql_fetch_array($userList) )
{
echo "<p>Name = " . $userInfo["name"] . ". Password = " . $userInfo["password"] . ".</p>";
if ($userInfo["password"] == $password)
{
echo "<p>The passwords match and are both $password!</p>";
}
else
{
echo "<p>$password does not match with " . $userInfo["password"] . "!</p>";
}
}
while ( ($userInfo = mysql_fetch_array($userList) ) && (!($found)) )
{
echo "The current username is " . $userInfo["name"] . ". <ul>";
if ($username == $userInfo["name"])
{
$found = true;
echo "<p>We found you in the database, " . $userInfo['name'] . ". Now to test your password.</p>";
if ($password == $userInfo['password'])
{
echo "<p>The password you entered, " . $userInfo['password'] . " was correct!</p>";
//now show the table's contents
$register = mysql_query("SELECT * FROM myTable;");
while ($col = mysql_fetch_array($register) )
{
echo "<li>Tag: " . $col['service_tag'] . "</li>";
}
}
else //the username is right but the password is wrong.
{
echo "The password didn't match, though!";
}
}
else //this username isn't the right one.
{
echo "<p>$username does not match " . $userInfo['name'] . ".";
}
echo "</ul>";
}
/*
*Test code: trying to output the testUsers info without the conditions.
*/
if (!$found)
{
echo "<p>We could not find you in the database. Did you enter your username correctly?</p>";
}
echo "</ul>";
mysql_close($connect);
}
?>
do {
//your code here to motion
}
while()// your conditions
在这种情况下,只要中的状态为true,而中的状态为true,do
将继续工作。完成第一个块后,光标位于$userList的末尾。因此,在第二个块中,没有更多的内容可供阅读
<head>
<title>My Web Interface</title>
</head>
<?php
if (!($_POST["go"]))
{
?><h1>Hello World!</h1>
<form action="test.php" method="post">
Username: <input type="text" name="username" /> <br />
Password: <input type="text" name="password" /> <br />
<input type="submit" name="go" />
</form>
<?php
}
else //the user has submitted: in which case, we check if the details match any user info in the database
{
$username = $_POST["username"];
$password = $_POST["password"];
//the database info variables
$hostname = "myhostname";
$dbUsername = "myusername";
$dbPassword = "mypassword";
echo "<p>You entered the username and password combo of '$username' and '$password'.</p>";
$connect = mysql_connect($hostname, $dbUsername, $dbPassword) or die ("Unable to connect to MySQL");
//test for the connection's presence. Every time so far it's returned True.
if ($connect)
{
echo "Got it!";
}
else
{
echo "Don't got it!";
}
//echo "<p>My username is " . $dbUsername ", my hostname is " . $hostname . " and my password is " . $dbPassword . ".</p>";
$selected = mysql_select_db("myDatabase",$connect)
or die("Could not select examples");
$userList = mysql_query("SELECT * FROM testUsers;");
/****
* This part tests to show a connection between the user and the database.
* It should return a list of users and the rights they have.
***
*/
$found = false; //how we terminate the loop.
//echo "<ul>";
while ($userInfo = mysql_fetch_array($userList) )
{
echo "<p>Name = " . $userInfo["name"] . ". Password = " . $userInfo["password"] . ".</p>";
if ($userInfo["password"] == $password)
{
echo "<p>The passwords match and are both $password!</p>";
}
else
{
echo "<p>$password does not match with " . $userInfo["password"] . "!</p>";
}
}
while ( ($userInfo = mysql_fetch_array($userList) ) && (!($found)) )
{
echo "The current username is " . $userInfo["name"] . ". <ul>";
if ($username == $userInfo["name"])
{
$found = true;
echo "<p>We found you in the database, " . $userInfo['name'] . ". Now to test your password.</p>";
if ($password == $userInfo['password'])
{
echo "<p>The password you entered, " . $userInfo['password'] . " was correct!</p>";
//now show the table's contents
$register = mysql_query("SELECT * FROM myTable;");
while ($col = mysql_fetch_array($register) )
{
echo "<li>Tag: " . $col['service_tag'] . "</li>";
}
}
else //the username is right but the password is wrong.
{
echo "The password didn't match, though!";
}
}
else //this username isn't the right one.
{
echo "<p>$username does not match " . $userInfo['name'] . ".";
}
echo "</ul>";
}
/*
*Test code: trying to output the testUsers info without the conditions.
*/
if (!$found)
{
echo "<p>We could not find you in the database. Did you enter your username correctly?</p>";
}
echo "</ul>";
mysql_close($connect);
}
?>
$userInfo = mysql_fetch_array($userList)
尝试在第二个块之前包含以下语句,以将光标移回第一个项:
<head>
<title>My Web Interface</title>
</head>
<?php
if (!($_POST["go"]))
{
?><h1>Hello World!</h1>
<form action="test.php" method="post">
Username: <input type="text" name="username" /> <br />
Password: <input type="text" name="password" /> <br />
<input type="submit" name="go" />
</form>
<?php
}
else //the user has submitted: in which case, we check if the details match any user info in the database
{
$username = $_POST["username"];
$password = $_POST["password"];
//the database info variables
$hostname = "myhostname";
$dbUsername = "myusername";
$dbPassword = "mypassword";
echo "<p>You entered the username and password combo of '$username' and '$password'.</p>";
$connect = mysql_connect($hostname, $dbUsername, $dbPassword) or die ("Unable to connect to MySQL");
//test for the connection's presence. Every time so far it's returned True.
if ($connect)
{
echo "Got it!";
}
else
{
echo "Don't got it!";
}
//echo "<p>My username is " . $dbUsername ", my hostname is " . $hostname . " and my password is " . $dbPassword . ".</p>";
$selected = mysql_select_db("myDatabase",$connect)
or die("Could not select examples");
$userList = mysql_query("SELECT * FROM testUsers;");
/****
* This part tests to show a connection between the user and the database.
* It should return a list of users and the rights they have.
***
*/
$found = false; //how we terminate the loop.
//echo "<ul>";
while ($userInfo = mysql_fetch_array($userList) )
{
echo "<p>Name = " . $userInfo["name"] . ". Password = " . $userInfo["password"] . ".</p>";
if ($userInfo["password"] == $password)
{
echo "<p>The passwords match and are both $password!</p>";
}
else
{
echo "<p>$password does not match with " . $userInfo["password"] . "!</p>";
}
}
while ( ($userInfo = mysql_fetch_array($userList) ) && (!($found)) )
{
echo "The current username is " . $userInfo["name"] . ". <ul>";
if ($username == $userInfo["name"])
{
$found = true;
echo "<p>We found you in the database, " . $userInfo['name'] . ". Now to test your password.</p>";
if ($password == $userInfo['password'])
{
echo "<p>The password you entered, " . $userInfo['password'] . " was correct!</p>";
//now show the table's contents
$register = mysql_query("SELECT * FROM myTable;");
while ($col = mysql_fetch_array($register) )
{
echo "<li>Tag: " . $col['service_tag'] . "</li>";
}
}
else //the username is right but the password is wrong.
{
echo "The password didn't match, though!";
}
}
else //this username isn't the right one.
{
echo "<p>$username does not match " . $userInfo['name'] . ".";
}
echo "</ul>";
}
/*
*Test code: trying to output the testUsers info without the conditions.
*/
if (!$found)
{
echo "<p>We could not find you in the database. Did you enter your username correctly?</p>";
}
echo "</ul>";
mysql_close($connect);
}
?>
mysql_data_seek($userList, 0);
或者更好:
<head>
<title>My Web Interface</title>
</head>
<?php
if (!($_POST["go"]))
{
?><h1>Hello World!</h1>
<form action="test.php" method="post">
Username: <input type="text" name="username" /> <br />
Password: <input type="text" name="password" /> <br />
<input type="submit" name="go" />
</form>
<?php
}
else //the user has submitted: in which case, we check if the details match any user info in the database
{
$username = $_POST["username"];
$password = $_POST["password"];
//the database info variables
$hostname = "myhostname";
$dbUsername = "myusername";
$dbPassword = "mypassword";
echo "<p>You entered the username and password combo of '$username' and '$password'.</p>";
$connect = mysql_connect($hostname, $dbUsername, $dbPassword) or die ("Unable to connect to MySQL");
//test for the connection's presence. Every time so far it's returned True.
if ($connect)
{
echo "Got it!";
}
else
{
echo "Don't got it!";
}
//echo "<p>My username is " . $dbUsername ", my hostname is " . $hostname . " and my password is " . $dbPassword . ".</p>";
$selected = mysql_select_db("myDatabase",$connect)
or die("Could not select examples");
$userList = mysql_query("SELECT * FROM testUsers;");
/****
* This part tests to show a connection between the user and the database.
* It should return a list of users and the rights they have.
***
*/
$found = false; //how we terminate the loop.
//echo "<ul>";
while ($userInfo = mysql_fetch_array($userList) )
{
echo "<p>Name = " . $userInfo["name"] . ". Password = " . $userInfo["password"] . ".</p>";
if ($userInfo["password"] == $password)
{
echo "<p>The passwords match and are both $password!</p>";
}
else
{
echo "<p>$password does not match with " . $userInfo["password"] . "!</p>";
}
}
while ( ($userInfo = mysql_fetch_array($userList) ) && (!($found)) )
{
echo "The current username is " . $userInfo["name"] . ". <ul>";
if ($username == $userInfo["name"])
{
$found = true;
echo "<p>We found you in the database, " . $userInfo['name'] . ". Now to test your password.</p>";
if ($password == $userInfo['password'])
{
echo "<p>The password you entered, " . $userInfo['password'] . " was correct!</p>";
//now show the table's contents
$register = mysql_query("SELECT * FROM myTable;");
while ($col = mysql_fetch_array($register) )
{
echo "<li>Tag: " . $col['service_tag'] . "</li>";
}
}
else //the username is right but the password is wrong.
{
echo "The password didn't match, though!";
}
}
else //this username isn't the right one.
{
echo "<p>$username does not match " . $userInfo['name'] . ".";
}
echo "</ul>";
}
/*
*Test code: trying to output the testUsers info without the conditions.
*/
if (!$found)
{
echo "<p>We could not find you in the database. Did you enter your username correctly?</p>";
}
echo "</ul>";
mysql_close($connect);
}
?>
if (!mysql_data_seek($userList, 0))
{
echo "You can't go back (seek): " . mysql_error() . "\n";
}
else
{
// Block 2
}
完成第一个块后,光标位于$userList的末尾。因此,在第二个块中,没有更多的内容可供阅读
<head>
<title>My Web Interface</title>
</head>
<?php
if (!($_POST["go"]))
{
?><h1>Hello World!</h1>
<form action="test.php" method="post">
Username: <input type="text" name="username" /> <br />
Password: <input type="text" name="password" /> <br />
<input type="submit" name="go" />
</form>
<?php
}
else //the user has submitted: in which case, we check if the details match any user info in the database
{
$username = $_POST["username"];
$password = $_POST["password"];
//the database info variables
$hostname = "myhostname";
$dbUsername = "myusername";
$dbPassword = "mypassword";
echo "<p>You entered the username and password combo of '$username' and '$password'.</p>";
$connect = mysql_connect($hostname, $dbUsername, $dbPassword) or die ("Unable to connect to MySQL");
//test for the connection's presence. Every time so far it's returned True.
if ($connect)
{
echo "Got it!";
}
else
{
echo "Don't got it!";
}
//echo "<p>My username is " . $dbUsername ", my hostname is " . $hostname . " and my password is " . $dbPassword . ".</p>";
$selected = mysql_select_db("myDatabase",$connect)
or die("Could not select examples");
$userList = mysql_query("SELECT * FROM testUsers;");
/****
* This part tests to show a connection between the user and the database.
* It should return a list of users and the rights they have.
***
*/
$found = false; //how we terminate the loop.
//echo "<ul>";
while ($userInfo = mysql_fetch_array($userList) )
{
echo "<p>Name = " . $userInfo["name"] . ". Password = " . $userInfo["password"] . ".</p>";
if ($userInfo["password"] == $password)
{
echo "<p>The passwords match and are both $password!</p>";
}
else
{
echo "<p>$password does not match with " . $userInfo["password"] . "!</p>";
}
}
while ( ($userInfo = mysql_fetch_array($userList) ) && (!($found)) )
{
echo "The current username is " . $userInfo["name"] . ". <ul>";
if ($username == $userInfo["name"])
{
$found = true;
echo "<p>We found you in the database, " . $userInfo['name'] . ". Now to test your password.</p>";
if ($password == $userInfo['password'])
{
echo "<p>The password you entered, " . $userInfo['password'] . " was correct!</p>";
//now show the table's contents
$register = mysql_query("SELECT * FROM myTable;");
while ($col = mysql_fetch_array($register) )
{
echo "<li>Tag: " . $col['service_tag'] . "</li>";
}
}
else //the username is right but the password is wrong.
{
echo "The password didn't match, though!";
}
}
else //this username isn't the right one.
{
echo "<p>$username does not match " . $userInfo['name'] . ".";
}
echo "</ul>";
}
/*
*Test code: trying to output the testUsers info without the conditions.
*/
if (!$found)
{
echo "<p>We could not find you in the database. Did you enter your username correctly?</p>";
}
echo "</ul>";
mysql_close($connect);
}
?>
$userInfo = mysql_fetch_array($userList)
尝试在第二个块之前包含以下语句,以将光标移回第一个项:
<head>
<title>My Web Interface</title>
</head>
<?php
if (!($_POST["go"]))
{
?><h1>Hello World!</h1>
<form action="test.php" method="post">
Username: <input type="text" name="username" /> <br />
Password: <input type="text" name="password" /> <br />
<input type="submit" name="go" />
</form>
<?php
}
else //the user has submitted: in which case, we check if the details match any user info in the database
{
$username = $_POST["username"];
$password = $_POST["password"];
//the database info variables
$hostname = "myhostname";
$dbUsername = "myusername";
$dbPassword = "mypassword";
echo "<p>You entered the username and password combo of '$username' and '$password'.</p>";
$connect = mysql_connect($hostname, $dbUsername, $dbPassword) or die ("Unable to connect to MySQL");
//test for the connection's presence. Every time so far it's returned True.
if ($connect)
{
echo "Got it!";
}
else
{
echo "Don't got it!";
}
//echo "<p>My username is " . $dbUsername ", my hostname is " . $hostname . " and my password is " . $dbPassword . ".</p>";
$selected = mysql_select_db("myDatabase",$connect)
or die("Could not select examples");
$userList = mysql_query("SELECT * FROM testUsers;");
/****
* This part tests to show a connection between the user and the database.
* It should return a list of users and the rights they have.
***
*/
$found = false; //how we terminate the loop.
//echo "<ul>";
while ($userInfo = mysql_fetch_array($userList) )
{
echo "<p>Name = " . $userInfo["name"] . ". Password = " . $userInfo["password"] . ".</p>";
if ($userInfo["password"] == $password)
{
echo "<p>The passwords match and are both $password!</p>";
}
else
{
echo "<p>$password does not match with " . $userInfo["password"] . "!</p>";
}
}
while ( ($userInfo = mysql_fetch_array($userList) ) && (!($found)) )
{
echo "The current username is " . $userInfo["name"] . ". <ul>";
if ($username == $userInfo["name"])
{
$found = true;
echo "<p>We found you in the database, " . $userInfo['name'] . ". Now to test your password.</p>";
if ($password == $userInfo['password'])
{
echo "<p>The password you entered, " . $userInfo['password'] . " was correct!</p>";
//now show the table's contents
$register = mysql_query("SELECT * FROM myTable;");
while ($col = mysql_fetch_array($register) )
{
echo "<li>Tag: " . $col['service_tag'] . "</li>";
}
}
else //the username is right but the password is wrong.
{
echo "The password didn't match, though!";
}
}
else //this username isn't the right one.
{
echo "<p>$username does not match " . $userInfo['name'] . ".";
}
echo "</ul>";
}
/*
*Test code: trying to output the testUsers info without the conditions.
*/
if (!$found)
{
echo "<p>We could not find you in the database. Did you enter your username correctly?</p>";
}
echo "</ul>";
mysql_close($connect);
}
?>
mysql_data_seek($userList, 0);
或者更好:
<head>
<title>My Web Interface</title>
</head>
<?php
if (!($_POST["go"]))
{
?><h1>Hello World!</h1>
<form action="test.php" method="post">
Username: <input type="text" name="username" /> <br />
Password: <input type="text" name="password" /> <br />
<input type="submit" name="go" />
</form>
<?php
}
else //the user has submitted: in which case, we check if the details match any user info in the database
{
$username = $_POST["username"];
$password = $_POST["password"];
//the database info variables
$hostname = "myhostname";
$dbUsername = "myusername";
$dbPassword = "mypassword";
echo "<p>You entered the username and password combo of '$username' and '$password'.</p>";
$connect = mysql_connect($hostname, $dbUsername, $dbPassword) or die ("Unable to connect to MySQL");
//test for the connection's presence. Every time so far it's returned True.
if ($connect)
{
echo "Got it!";
}
else
{
echo "Don't got it!";
}
//echo "<p>My username is " . $dbUsername ", my hostname is " . $hostname . " and my password is " . $dbPassword . ".</p>";
$selected = mysql_select_db("myDatabase",$connect)
or die("Could not select examples");
$userList = mysql_query("SELECT * FROM testUsers;");
/****
* This part tests to show a connection between the user and the database.
* It should return a list of users and the rights they have.
***
*/
$found = false; //how we terminate the loop.
//echo "<ul>";
while ($userInfo = mysql_fetch_array($userList) )
{
echo "<p>Name = " . $userInfo["name"] . ". Password = " . $userInfo["password"] . ".</p>";
if ($userInfo["password"] == $password)
{
echo "<p>The passwords match and are both $password!</p>";
}
else
{
echo "<p>$password does not match with " . $userInfo["password"] . "!</p>";
}
}
while ( ($userInfo = mysql_fetch_array($userList) ) && (!($found)) )
{
echo "The current username is " . $userInfo["name"] . ". <ul>";
if ($username == $userInfo["name"])
{
$found = true;
echo "<p>We found you in the database, " . $userInfo['name'] . ". Now to test your password.</p>";
if ($password == $userInfo['password'])
{
echo "<p>The password you entered, " . $userInfo['password'] . " was correct!</p>";
//now show the table's contents
$register = mysql_query("SELECT * FROM myTable;");
while ($col = mysql_fetch_array($register) )
{
echo "<li>Tag: " . $col['service_tag'] . "</li>";
}
}
else //the username is right but the password is wrong.
{
echo "The password didn't match, though!";
}
}
else //this username isn't the right one.
{
echo "<p>$username does not match " . $userInfo['name'] . ".";
}
echo "</ul>";
}
/*
*Test code: trying to output the testUsers info without the conditions.
*/
if (!$found)
{
echo "<p>We could not find you in the database. Did you enter your username correctly?</p>";
}
echo "</ul>";
mysql_close($connect);
}
?>
if (!mysql_data_seek($userList, 0))
{
echo "You can't go back (seek): " . mysql_error() . "\n";
}
else
{
// Block 2
}
请注意,您没有回显“密码不匹配!”;
,如果不是打字错误,这将引发错误。回显“您输入的密码”.$userInfo['password']”是正确的!”;
-文字无法表达这是多么可怕的想法。1)永远不要以纯文本形式存储密码。2)永远不要显示密码。(注意:如果您遵循步骤1,您将自动获得步骤2。)此外,如果登录失败,只需告诉用户登录失败。你给他们的信息太多了。“用户名不匹配”、“密码不匹配”,这是太多的错误信息。您确实应该在查询中使用where
子句,因此您只会首先返回匹配的行。想象一下,如果谷歌有这个登录系统,必须输出20亿个“不匹配”行和一行您的登录信息实际成功。您从哪里获得$username
和$password
?此外,mysql\u查询也不推荐使用。查看mySQLi或PDO。我也赞同其他评论的关切。为什么要显示密码或将其存储为明文?您可以使用WHERE
子句在查询中完成所有这些操作其中username=$username和password=$password
如果结果为零,则不存在匹配项。好吧,除了前面提到的几点之外:$userInfo
包含哪些内容?请注意,您没有回应“但是密码不匹配!”
如果不是输入错误,则会抛出错误。回显“您输入的密码”$userInfo['password']。“没错!”代码>-语言无法表达这是多么可怕的想法。1) 永远不要以纯文本形式存储密码。2) 永远不要显示密码。(注意:如果您遵循步骤1,您将自动获得步骤2。)此外,如果登录失败,只需告诉用户登录失败。你给他们的信息太多了。“用户名不匹配”,“密码不匹配”,这是太多的错误信息。你真的很生气