0
確定這裏是情況,我想使用登錄表單PHP表單,如何在同一頁面上回顯?
<form name="form1" method="post" action="sign.php">
Username:<br/>
<input name="myusername" type="text" id="myusername" /><br />
Password:<br />
<input name="mypassword" type="text" id="mypassword" /><br />
<input type="submit" name="Submit" value="Login" />
</form>
sign.php
<?php
ob_start();
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="cosmos"; // Database name
$tbl_name="members"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// Define $myusername and $mypassword
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$mypassword = md5($mypassword);
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
ob_end_flush();
?>
在情況下,如果用戶輸入錯誤的詳細信息,然後我想這顯示等形式的東西一樣......「錯誤的用戶名或密碼的同一頁上,請再試一次......「,我們在底部形成
如果你需要在表單標籤後面換行符,將它包裝在一個'label'元素中(它們對這類事情很有用,請參閱;)並給它顯示:block' – 2010-08-28 15:59:20
實際上這個是演示形式:),謝謝 – 2010-08-28 16:01:29