wrathican Posted July 2, 2007 Share Posted July 2, 2007 hi im having a problem with my login system heres my login page: <?php // session_start(); include '../include/switch.inc'; include '../include/misc.inc'; include '../include/opendb.inc'; $errorMessage = ''; if (isset($_POST['txtUserId']) && isset($_POST['txtPassword'])) { $userId = $_POST['txtUserId']; $password = $_POST['txtPassword']; // check if the user id and password combination exist in database $sql = "SELECT user_name FROM cy_user WHERE user_name = '$userId' AND user_pass = PASSWORD('$password')"; $result = mysql_query($sql); if (mysql_num_rows($result) == 1) { // the user id and password match, // set the session $_SESSION['db_is_logged_in'] = true; // after login we move to the main page header('Location: cms.php'); exit; } else { $errorMessage = 'Sorry, wrong user id / password'; } } ?> <HTML> <HEAD> <TITLE>CycleYorkshire.co.uk: Content Management System</TITLE> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> <link rel="stylesheet" type="text/css" href="../cy.css"> </HEAD> <BODY BGCOLOR=#FFFFFF LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0><center> <!-- ImageReady Slices (layout_concept3.psd) --> <TABLE WIDTH=800 BORDER=0 CELLPADDING=0 CELLSPACING=0> <!--DWLayoutTable--> <TR> <TD height="301" COLSPAN=2 valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0"> <!--DWLayoutTable--> <tr> <TD width="800" height="11" valign="top"> <IMG SRC="../images/cycleyorkshirebase_01.gif" WIDTH=800 HEIGHT=11 ALT=""></TD> </tr> <tr> <TD height="290" valign="top"> <a href="index.php"><IMG SRC="../images/cycleyorkshirebase_02.gif" ALT="" WIDTH=800 HEIGHT=290 border="0"></a></TD> </tr> </table> </TD> </TR> <TR> <TD width="216" height="751" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0"> <!--DWLayoutTable--> <tr> <TD width="200" height="23" valign="top"> <IMG SRC="../images/cycleyorkshirebase_03.gif" WIDTH=200 HEIGHT=23 ALT=""></TD> <td width="16" rowspan="5" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0"> <!--DWLayoutTable--> <tr> <td width="16" height="751"> </td> </tr> </table> </td> </tr> <tr> <TD height="420" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0"> <!--DWLayoutTable--> <tr> <?php include '../include/navicms.inc'; ?> </tr> </table></TD> </tr> <tr> <TD height="58" valign="top"> <IMG SRC="../images/cycleyorkshirebase_26.gif" WIDTH=200 HEIGHT=58 ALT=""></TD> </tr> <tr> <TD height="19" valign="top"><p><?php //get the 'this weekend' and display $query = "SELECT * FROM cy_weekend"; $result = mysql_query($query); while($row = mysql_fetch_array($result,MYSQL_NUM)) { $body = $row[1]; } echo $body;?></p></TD> </tr> <tr> <TD height="231" valign="top"> <IMG SRC="../images/cycleyorkshirebase_30.gif" WIDTH=200 HEIGHT=231 ALT=""></TD> </tr> </table></TD> <TD width="584" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0"> <!--DWLayoutTable--> <tr> <TD height="19" colspan="2" valign="top"><h1>Please login to the CMS</h1></TD> </tr> <tr> <TD height="19" colspan="2" valign="top"><p>Please enter login details below:<br /> <br /> Username:<br /> <form action="login.php" method="post"> <input type="text" name="textfield" /> <br /> Password:<br /> <input type="password" name="textfield2" /> <br /> <br /> <input type="submit" name="Submit" value="Submit" /></form></p></TD> </tr> <tr> <TD height="1"> </TD> <TD></TD> </tr> </table></TD> </TR> <TR> </center> </BODY> </HTML> when i submit the form i just see the form again.... it should redirect me to another page but it doesnt... and i dont get any errors Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted July 2, 2007 Share Posted July 2, 2007 Change ur code to this and try it: <?php session_start(); include '../include/switch.inc'; include '../include/misc.inc'; include '../include/opendb.inc'; $errorMessage = ''; if (isset($_POST['txtUserId']) && isset($_POST['txtPassword'])) { $userId = $_POST['txtUserId']; $password = $_POST['txtPassword']; // check if the user id and password combination exist in database $sql = "SELECT user_name FROM cy_user WHERE user_name = '$userId' AND user_pass = PASSWORD('$password')"; $result = mysql_query($sql); if (mysql_num_rows($result) == 1) { // the user id and password match, // set the session $_SESSION['db_is_logged_in'] = true; // after login we move to the main page header('Location: cms.php'); exit; } else { $errorMessage = 'Sorry, wrong user id / password'; } } else { ?> <HTML> <HEAD> <TITLE>CycleYorkshire.co.uk: Content Management System</TITLE> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> <link rel="stylesheet" type="text/css" href="../cy.css"> </HEAD> <BODY BGCOLOR=#FFFFFF LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0><center> <!-- ImageReady Slices (layout_concept3.psd) --> <TABLE WIDTH=800 BORDER=0 CELLPADDING=0 CELLSPACING=0> <!--DWLayoutTable--> <TR> <TD height="301" COLSPAN=2 valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0"> <!--DWLayoutTable--> <tr> <TD width="800" height="11" valign="top"> <IMG SRC="../images/cycleyorkshirebase_01.gif" WIDTH=800 HEIGHT=11 ALT=""></TD> </tr> <tr> <TD height="290" valign="top"> <a href="index.php"><IMG SRC="../images/cycleyorkshirebase_02.gif" ALT="" WIDTH=800 HEIGHT=290 border="0"></a></TD> </tr> </table> </TD> </TR> <TR> <TD width="216" height="751" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0"> <!--DWLayoutTable--> <tr> <TD width="200" height="23" valign="top"> <IMG SRC="../images/cycleyorkshirebase_03.gif" WIDTH=200 HEIGHT=23 ALT=""></TD> <td width="16" rowspan="5" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0"> <!--DWLayoutTable--> <tr> <td width="16" height="751"> </td> </tr> </table> </td> </tr> <tr> <TD height="420" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0"> <!--DWLayoutTable--> <tr> <?php include '../include/navicms.inc'; ?> </tr> </table></TD> </tr> <tr> <TD height="58" valign="top"> <IMG SRC="../images/cycleyorkshirebase_26.gif" WIDTH=200 HEIGHT=58 ALT=""></TD> </tr> <tr> <TD height="19" valign="top"><p><?php //get the 'this weekend' and display $query = "SELECT * FROM cy_weekend"; $result = mysql_query($query); while($row = mysql_fetch_array($result,MYSQL_NUM)) { $body = $row[1]; } echo $body;?></p></TD> </tr> <tr> <TD height="231" valign="top"> <IMG SRC="../images/cycleyorkshirebase_30.gif" WIDTH=200 HEIGHT=231 ALT=""></TD> </tr> </table></TD> <TD width="584" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0"> <!--DWLayoutTable--> <tr> <TD height="19" colspan="2" valign="top"><h1>Please login to the CMS</h1></TD> </tr> <tr> <TD height="19" colspan="2" valign="top"><p>Please enter login details below:<br /> <br /> Username:<br /> <form action="login.php" method="post"> <input type="text" name="textfield" /> <br /> Password:<br /> <input type="password" name="textfield2" /> <br /> <br /> <input type="submit" name="Submit" value="Submit" /></form></p></TD> </tr> <tr> <TD height="1"> </TD> <TD></TD> </tr> </table></TD> </TR> <TR> </center> </BODY> </HTML> <?php } ?> Quote Link to comment Share on other sites More sharing options...
wrathican Posted July 2, 2007 Author Share Posted July 2, 2007 i dont know what u changed but it still doesnt work. Quote Link to comment Share on other sites More sharing options...
wrathican Posted July 2, 2007 Author Share Posted July 2, 2007 omg i fixed it. i hadnt named the text fields... Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted July 2, 2007 Share Posted July 2, 2007 I just add else { Ur html code <?php } ?> Bcoz if user did not enter username or password than redirect him to login page. Other yes ur textfields name were wrong u get it, thats fine. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.