有关验证消息的问题。用户提交表单后,我的表单验证消息(通过php)出现在标题中。
如何让消息显示在正文中(在表单下方)。代码如下。 Screen shot attached for clarification
<?
/* Check User Script */
session_start(); // Start Session
include 'db.php';
// Conver to simple variables
$username = $_POST['username'];
$password = $_POST['password'];
if((!$username) || (!$password)){
echo "Please enter ALL of the information! <br />";
include 'login_form.html';
exit();
}
// Convert password to md5 hash
$password = md5($password);
// check if the user info validates the db
$sql = mysql_query("SELECT
*
FROM users u
WHERE
username='$username'
AND password='$password'
AND activated='1'
AND u.email_address IN (SELECT email from authorized_doctors)
");
$login_check = mysql_num_rows($sql);
if($login_check > 0){
while($row = mysql_fetch_array($sql)){
foreach( $row AS $key => $val ){
$$key = stripslashes( $val );
}
// Register some session variables!
session_start('first_name');
$_SESSION['first_name'] = $first_name;
session_start('last_name');
$_SESSION['last_name'] = $last_name;
session_start('email_address');
$_SESSION['email_address'] = $email_address;
session_start('special_user');
$_SESSION['user_level'] = $user_level;
mysql_query("UPDATE users SET last_login=now() WHERE
userid='$userid'");
header("Location: login_success.php");
}
} else {
echo "<br>You could not be logged in! Either the username and
password do not match or you have not validated your membership!
Please try again!<br />";
include 'login_form.html';
}
?>
答案 0 :(得分:1)
只需在include
之后输出您想要的数据:
...
} else {
include 'login_form.html';
echo "<br>You could not be logged in! Either the
username and password do not match or you have not validated your membership!
Please try again!<br />";
}
?>
答案 1 :(得分:1)
您可以将消息分配给变量,并将该变量输出到所需的位置。例如:
$message = '<br>You could not be logged in! Either the username and
password do not match or you have not validated your membership!
Please try again!<br />';
include 'login_form.php';
在login_form.php中的内容如下:
...
<a href="">Forgot password?</a>
<?php echo $message; ?>
...