我試圖在同一頁面上顯示錯誤消息。我知道我必須使用JavaScript。這是我的代碼到目前爲止。然而它後面說1。我thnk這是從我的numrows!== 0我將如何擺脫這1. 1.登錄同一頁面時顯示錯誤消息
<?php
session_start();
$username = $_POST['username'];
$password = $_POST['password'];
if ($username&&$password)
{
$host_name = 'localhost';
$db_user ='root';
$db_pass = '';
$db_name = 'login';
/* Connect to MySQL */
$con = mysql_connect("$host_name","$db_user","$db_pass") or die ("Couldn't connect!");
$db = mysql_select_db("$db_name") or die ("Couldn't connect to database!");
$query = mysql_query("SELECT * FROM users WHERE username='$username'");
$numrows = mysql_num_rows($query);
if ($numrows!=0)
{
while ($row = mysql_fetch_assoc($query))
{
$dbusername = $row['username'];
$dbpassword = $row['password'];
}
/*Check to see if they match! */
if ($username==$dbusername&&$password==$dbpassword)
{
echo "You're in! <a href='member.php'> Click</a> here to enter the member page";
$_SESSION['username']==$username;
}
else
echo "Incorrect password";
}
else
die("That user doesn't exist!");
echo $numrows;
}
else
die("Please enter username and/or password!");
?>
你的代碼很容易被mysql注入 – Fabio
只要刪除echo $ numrows; –
好的,謝謝,請指教在java – user3369387