PHP and HTML code mixed, PHP run error

Source: Internet
Author: User
Novice, the beginning of the code to write out what the problem is not, the result of today's browsing when the following situation, where is wrong?
ZXCVBNM Welcome to the arrival page click Back to retry "); } if (!isset ($_post[' submit ')) {exit (' illegal login! '); } $username =htmlspecialchars ($_post[' username '); $pwd =md5 ($_post[' pwd '); Include (' conn.php '); $check _user=mysql_query ("Select UserID from users where username = '". $username. "' and pwd = '". $pwd. "' Limit 1", $conn); if ($result =mysql_fetch_array ($check _user)) {$_session[' username ']= $result [' $username ']; $_session[' userid ']=$ result[' UserID ']; echo $username. " Welcome to click to enter the homepage "; }else{exit ("Login failed! Click Back to retry "); }?> Click to enter the homepage "; }else{exit ("Login failed! Click Back to retry "); }?> [color= #800000]
Here's the code:




<title>User Login</title>



Session_Start ();
if ($_get[' action ' ==logout]) {
unset ($_session[' username ');
unset ($_session[' userid ');
Exit (' Logout succeeded! '); Click Back to retry
}
if (!isset ($_post[' submit ')) {
Exit (' Illegal login! ');
}
$username =htmlspecialchars ($_post[' username ');
$pwd =md5 ($_post[' pwd ');
Include (' conn.php ');
$check _user= @mysql_query ("Select UserID from users where username = '". $username. "' and pwd = '". $pwd. "' Limit 1", $conn);
if ($result =mysql_fetch_array ($check _user)) {
$_session[' username ']= $result [' $username '];
$_session[' userid ']= $result [' userid '];
echo $username. " Welcome to click to enter the homepage ";
}else{
Exit ("Login failed! Click Back to retry ");
}
?>
Click Back to retry "); } if (!isset ($_post[' submit ')) {exit (' illegal login! '); } $username =htmlspecialchars ($_post[' username '); $pwd =md5 ($_post[' pwd '); Include (' conn.php '); $check _user=mysql_query ("Select UserID from users where username = '". $username. "' and pwd = '". $pwd. "' Limit 1", $conn); if ($result =mysql_fetch_array ($check _user)) {$_session[' username ']= $result [' $username ']; $_session[' userid ']=$ result[' UserID ']; echo $username. " Welcome to click to enter the homepage "; }else{exit ("Login failed! Click Back to retry "); }?> Click to enter the homepage "; }else{exit ("Login failed! Click Back to retry "); }?>



Reply to discussion (solution)

Exit ("Login failed! Click Back to retry ");
}
?>
Click Back to retry "); } if (!isset ($_post[' submit ')) {exit (' illegal login! '); } $

What are you looking at, a mess of code?

?>
Click Back to retry "); } if (!isset ($_post[' submit ')) {exit (' illegal login! '); } $username =htmlspecialchars ($_post[' username '); $pwd =md5 ($_post[' pwd '); Include (' conn.php '); $check _user=mysql_query ("Select UserID from users where username = '". $username. "' and pwd = '". $pwd. "' Limit 1", $conn); if ($result =mysql_fetch_array ($check _user)) {$_session[' username ']= $result [' $username ']; $_session[' userid ']=$ result[' UserID ']; echo $username. " Welcome to click to enter the homepage "; }else{exit ("Login failed! Click Back to retry "); }?> Click to enter the homepage "; }else{exit ("Login failed! Click Back to retry "); }?>
The comparison with the forgotten deleted, deleted after the visit will also appear in the above paragraph

if ($result =mysql_fetch_array ($check _user)) {
$_session[' username ']= $result [' $username '];
$_session[' userid ']= $result [' userid '];
echo $username. " Welcome to click to enter the homepage ";
}else{
Exit ("Login failed! Click Back to retry ");
}
?>
Click Back to retry "); } if (!isset ($_post[' submit ')) {exit (' illegal login! '); } $username =htmlspecialchars ($_post[' username '); $pwd =md5 ($_post[' pwd '); Include (' conn.php '); $check _user=mysql_query ("Select UserID from users where username = '". $username. "' and pwd = '". $pwd. "' Limit 1", $conn); if ($result =mysql_fetch_array ($check _user))


The red?> is superfluous, it is removed, and it causes the code below to become normal HTML.

What's your code now? Post an organized code

No, after the deletion, there will be this situation, it seems that the browser in the identification of the first HTML code, and it as a, the end of execution, the following code in the browser, text display

Session_Start ();
if ($_get[' action ' ==logout]) {
unset ($_session[' username ');
unset ($_session[' userid ');
Exit (' Logout succeeded! '); Click Back to retry
}
if (!isset ($_post[' submit ')) {
Exit (' Illegal login! ');
}
$username =htmlspecialchars ($_post[' username ');
$pwd =md5 ($_post[' pwd ');
Include (' conn.php ');
$check _user= @mysql_query ("Select UserID from users where username = '". $username. "' and pwd = '". $pwd. "' Limit 1", $conn);
if ($result =mysql_fetch_array ($check _user)) {
$_session[' username ']= $result [' $username '];
$_session[' userid ']= $result [' userid '];
echo $username. " Welcome to click to enter the homepage ";
}else{
Exit ("Login failed! Click Back to retry ");
}
?>

Is this the code for the entire page? Not all of it?

The page should be the beginning of the code you send the second half ~ ~ The whole deletion of the problem, check the cache, or copy the code into a test file, run it, (recommended directly in the server working directory, do not project) with localhost to access, see also come out?

Before the cache has been cleaned up, no use, another folder is the same, the file is placed in the server working directory with localhost to access,

Here are the login.php:
if ($_cookie[' username ']!= "") {
$username =$_cookie[' username '];
}
if ($_cookie[' pwd ']!= "") {
$pwd =$_cookie[' pwd '];
}
?>


User Login


if (Isset ($_post[' submit ')) and $_post[' Submit ']== "submit") {
$username =$_post[' username '];
$pwd =$_post[' pwd '];
if ($_cookie[' pwd ']!= $pwd) {
$pwd =md5 ($_post[' pwd ');
}
if ($remember!=0) {
$remember =$_post[' remember '];
Setcookie ("username", $username, Time () + $remember *3600*24);
Setcookie ("pwd", $pwd, Time () + $remember *3600*24);
Setcookie ("Remember", $pwd, Time () + $remember *3600*24);
}
}
?>
Here are the login_ok.php:
Session_Start ();
if ($_get[' action ']==logout) {
unset ($_session[' username ');
unset ($_session[' userid ');
Exit (' Logout succeeded! '); Click Back to retry
}
if (!isset ($_post[' submit ')) {
Exit (' Illegal login! ');
}
$username =htmlspecialchars ($_post[' username ');
$pwd =md5 ($_post[' pwd ');
Include (' conn.php ');
$check _user= @mysql_query ("Select UserID from users where username = '". $username. "' and pwd = '". $pwd. "' Limit 1", $conn);
if ($result =mysql_fetch_array ($check _user)) {
$_session[' username ']= $result [' $username '];
$_session[' userid ']= $result [' userid '];
echo $username. " Welcome to click to enter the homepage ";
}else{
Exit ("Login failed! Click Back to retry ");
}
?>
The following are the linked databases:
$conn = @mysql_connect ("localhost", "root", "137733") or Die ("L½??? §°?¡ ". Mysql_error ());
mysql_select_db ("Hexie", $conn);
mysql_query ("Set character set UTF8");
mysql_query ("Set names UTF8");
?>

I probably saw nothing wrong.
$check _user= @mysql_query ("Select UserID from users where username = '". $username. "' and pwd = '". $pwd. "' Limit 1", $conn);
if ($result =mysql_fetch_array ($check _user)) {
$_session[' username ']= $result [' $username '];
$_session[' userid ']= $result [' userid '];
echo $username. " Welcome to click to enter the homepage ";
}else{
Exit ("Login failed! Click Back to retry ");
}

Just here select UserID from you only query a field, below the $result[' $username '];
There's no use, there's a mistake.

That's not the point.
Exit (' Logout succeeded! '); Click Back to retry
History.back ( -1); "> To this > deadline, the browser thinks that the PHP code is over, even if there is a mistake to identify it

F ($_get[' action ' ==logout]) {???
What kind of grammar is this?
if ($_get[' action ']==logout) {
What kind of grammar is this?

Why do you have to write your code while asking questions, instead of copying and pasting it?

The original is copy and paste, I first made a few mentally retarded errors, and then I checked the discovery and changed, and now the browser preview effect is
Click to enter the homepage ";
}else{
Exit ("Login failed! Click Back to retry ");
}
?>

Only you can "copy and paste" the possibility to help you find the error

Do not have a special put the tag of the code to use the copy come in such a good look at the chaos ... Dizzy...

Session_Start ();
Put it on the first line.

Incredibly still can reply, I also recently encountered this problem, finally found the reason. The mixed-encoding suffix name must be. php,.html a problem with PHP code parsing errors. See here, OK. Http://zhidao.baidu.com/link?url=GTeO4AmQJjdjvHXK3SrLQ5bonVuD_35RtDED1gcsu6Z4bLsJ0hBwlon8wp7aErvbNTjz9R0RP8CqQqNIXdhRyq

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.