Php and html code mixed writing, php running error novice, no problem at the beginning of code writing, the result is today when browsing the following situation, where is the error?
Welcome to zxcvbnm click to enter the home page and click return to retry ");} if (! Isset ($ _ POST ['submit ']) {exit ('illegal logon! ') ;}$ 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 the homepage";} else {exit ("logon failed! Click Return to retry ") ;}?> Click to go to the homepage ";} else {exit (" logon failed! Click Return to retry ") ;}?> [Color = #1, 800000]
The following code is used:
User Login
Session_start ();
If ($ _ GET ['action' = logout]) {
Unset ($ _ SESSION ['username']);
Unset ($ _ SESSION ['userid']);
Exit ('logout successful! Click "return retry ');
}
If (! Isset ($ _ POST ['submit ']) {
Exit ('illegal logon! ');
}
$ 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 the homepage ";
} Else {
Exit ("logon failed! Click Return to retry ");
}
?>
Click return retry ");} if (! Isset ($ _ POST ['submit ']) {exit ('illegal logon! ') ;}$ 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 the homepage";} else {exit ("logon failed! Click Return to retry ") ;}?> Click to go to the homepage ";} else {exit (" logon failed! Click Return to retry ") ;}?>
Reply to discussion (solution)
Exit ("logon failed! Click Return to retry ");
}
?>
Click return retry ");} if (! Isset ($ _ POST ['submit ']) {exit ('illegal logon! ');} $
How can I look at the messy code?
?>
Click return retry ");} if (! Isset ($ _ POST ['submit ']) {exit ('illegal logon! ') ;}$ 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 the homepage";} else {exit ("logon failed! Click Return to retry ") ;}?> Click to go to the homepage ";} else {exit (" logon failed! Click Return to retry ") ;}?>
If you forget to delete the items used for comparison, the above section will appear during browsing.
If ($ result = mysql_fetch_array ($ check_user )){
$ _ SESSION ['username'] = $ result ['$ username'];
$ _ SESSION ['userid'] = $ result ['userid'];
Echo $ username. "Welcome to the homepage ";
} Else {
Exit ("logon failed! Click Return to retry ");
}
?>
Click return retry ");} if (! Isset ($ _ POST ['submit ']) {exit ('illegal logon! ') ;}$ 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 ))
Red?> Redundant, just remove it. it causes the code below it to become a common html
What is your current code? Publish a sorted code
It's useless. after deletion, this will happen again. it seems that the browser is recognizing the first html code> and regards it as?>, After the execution is completed, the code is displayed in text in the browser.
Session_start ();
If ($ _ GET ['action' = logout]) {
Unset ($ _ SESSION ['username']);
Unset ($ _ SESSION ['userid']);
Exit ('logout successful! Click "return retry ');
}
If (! Isset ($ _ POST ['submit ']) {
Exit ('illegal logon! ');
}
$ 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 the homepage ";
} Else {
Exit ("logon failed! Click Return to retry ");
}
?>
Is this code for the entire page? Not all, right?
The page displays the second half of the code you are sending ~~ If there is still a problem with the entire deletion, check the cache, or copy the code to a test file and run it. (it is recommended to directly store the code in the working directory of the server, rather than project) use localhost for access, are you sure you want to continue?
The cache has been cleared before, and it is useless. The same is true for changing a folder. files are stored in the working directory of the server and accessed using localhost,
The following is login. php:
If ($ _ COOKIE ['username']! = ""){
$ Username = $ _ COOKIE ['username'];
}
If ($ _ COOKIE ['pwd']! = ""){
$ Pwd = $ _ COOKIE ['pwd'];
}
?>
User logon
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 );
}
}
?>
The following is login_ OK .php:
Session_start ();
If ($ _ GET ['action'] = logout ){
Unset ($ _ SESSION ['username']);
Unset ($ _ SESSION ['userid']);
Exit ('logout successful! Click "return retry ');
}
If (! Isset ($ _ POST ['submit ']) {
Exit ('illegal logon! ');
}
$ 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 the homepage ";
} Else {
Exit ("logon failed! Click Return to retry ");
}
?>
The following links to the database:
$ Conn = @ mysql_connect ("localhost", "root", "137733") or die ("l login ??? § °? Parser ". mysql_error ());
Mysql_select_db ("hexie", $ conn );
Mysql_query ("set character set utf8 ");
Mysql_query ("set names utf8 ");
?>
I have read about the error.
$ 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 the homepage ";
} Else {
Exit ("logon failed! Click Return to retry ");
}
Only select userid from here you can query only one field, the following $ result ['$ username'];
There is an error.
This is not the key,
Exit ('logout successful! Click "return retry ');
History. back (-1); "> by now> As of now, the browser will think that the php code is over, and the code cannot be identified even if something goes wrong.
F ($ _ GET ['action' = logout]) {???
What is this syntax?
If ($ _ GET ['action'] = logout ){
What is this syntax?
Why do you need to write your code while asking questions, instead of copying and pasting your code?
It turned out to be copy and paste. At first I made some mental retardation errors. later I checked and found that I changed it again. now the browser preview effect is
Click to enter the home page ";
} Else {
Exit ("logon failed! Click Return to retry ");
}
?>
Only the "copy and paste" operator can help you identify errors.
Isn't there a dedicated code tag? it looks messy to copy it in like that...
Session_start ();
Put in the first line
I can still reply to this question. I recently encountered this problem and finally found the cause. If the suffix of "mix" is ".php" and ".html", the php code parsing error will occur. OK. Http://zhidao.baidu.com/link? Url = response