steviez Posted January 31, 2007 Share Posted January 31, 2007 Hi,I have a login page on my site and when a user navigates to it its always says the error message for an empty login form. what have i done wrong?My code:[code]<?php ob_start(); include("connect.php"); include("header.php"); $query = "select * from user where username ='".$_POST[username]."' and password='".$_POST[password]."'"; $result = mysql_query($query); $total = mysql_num_rows($result); if($total < 1) { $login=error; } else { if(isset($UsErId)) { setcookie("UsErId","","0","/"); $UsErId=""; } $row = mysql_fetch_array($result); setcookie("UsErId",$row[id],"0","/"); $mydate = date("Y-m-d"); $update_user = "update user set login = '$mydate',login_status = 'Online!' where id = '$row[id]' and status = 'ACTIVE'"; $update_result = mysql_query($update_user); header("Location:index.php?ch=i"); }?> <table align="center" width="780" class="frame"> <tr> <td valign="top"><table width="780" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="6"><img src="images/1x1.gif" width="1" height="1"></td> <td align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td align="left" valign="top"> </td> </tr> <tr> <td align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td height="13" align="left" valign="top"><img src="images/1x1.gif" width="1" height="1"></td> </tr> <tr> <td align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="11" class="lshadow"> </td> <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="28"> </td> <td width="100%" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td> </td> </tr> <tr> <td><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td align="left" valign="top"> </td> <td> </td> <td width="25" align="right" valign="top"> </td> </tr> <tr> <td width="25" align="left" class="lshadowwhite"> </td> <td align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="16%" align="left"><table class="page_content_frame" width="100%" border="0" cellspacing="2" cellpadding="0"> <tr> <td class="darkblue12"> <br></td> </tr> <tr> <td> </td> </tr> <tr> <td align="center"> <?php if($login==error) { ?> <font color="#FF0000"> <? echo $lang['Invalid_msg']; ?> </font> <?php } ?> </td> </tr> <tr> <td> </td> </tr> <form name="login" method="post" action="login.php"> <tr> <td align="center"><table width="30%" border="0" cellspacing="2" cellpadding="2"> <tr> <td width="20%"> <? echo $lang['user_name']; ?> :</td> <td width="80%"><input name="username" type="text" class="txtfield"></td> </tr> <tr> <td> <? echo $lang['Password']; ?> :</td> <td><input name="password" type="password" class="txtfield"></td> </tr> <tr> <td> </td> <td><div align="left"><B> <? echo $lang['Forgot']; ?> :</B> <A href="forgotuser.php"> <? echo $lang['username']; ?> </A> | <A href="forgotpass.php"> <? echo $lang['Password']; ?> </A></div></td> </tr> <tr> <td> </td> <td><INPUT name=submit type=submit class="button" value="GO"></td> </tr> </table></td> </tr> </form> </table></td> </tr> </table></td> </tr> </table></td> <td align="right" class="rshadowwhite"> </td> </tr> <tr> <td align="left"> </td> <td class="bottomshadowwhite"> </td> <td align="right"> </td> </tr> </table></td> </tr> <tr> <td> </td> </tr> </table></td> </tr> </table></td> </tr> </table></td> <td width="10" class="rshadow"> </td> </tr> </table></td> </tr> <tr> <td height="16" align="left" valign="top"><img src="images/1x1.gif" width="1" height="1"></td> </tr> </table></td> </tr> <tr> <td align="left" valign="top"><?php include("bottom.php")?></td> </tr> </table></td> <td width="6"><img src="images/1x1.gif" width="1" height="1"></td> </tr> </table></td> </tr> </table></body></html>[/code] Link to comment https://forums.phpfreaks.com/topic/36417-solved-login-help/ Share on other sites More sharing options...
rantsh Posted January 31, 2007 Share Posted January 31, 2007 [quote author=steviez link=topic=124796.msg517575#msg517575 date=1170204380][code]setcookie("UsErId",$row[id],"0","/");[/code][/quote]Your cookie expiration is set to 0 Link to comment https://forums.phpfreaks.com/topic/36417-solved-login-help/#findComment-173244 Share on other sites More sharing options...
steviez Posted January 31, 2007 Author Share Posted January 31, 2007 [quote author=rantsh link=topic=124796.msg517579#msg517579 date=1170205161][quote author=steviez link=topic=124796.msg517575#msg517575 date=1170204380][code]setcookie("UsErId",$row[id],"0","/");[/code][/quote]Your cookie expiration is set to 0[/quote]Still no joy, thank for trying though Link to comment https://forums.phpfreaks.com/topic/36417-solved-login-help/#findComment-173256 Share on other sites More sharing options...
corbin Posted January 31, 2007 Share Posted January 31, 2007 Your script is checking the DB with variables that don't exist so it's returning 0 rows, thus creating the error... You need to add a if($_POST) condition before the error checking so it will only error check if the $_POST variables are set.... Link to comment https://forums.phpfreaks.com/topic/36417-solved-login-help/#findComment-173265 Share on other sites More sharing options...
steviez Posted January 31, 2007 Author Share Posted January 31, 2007 [quote author=corbin link=topic=124796.msg517600#msg517600 date=1170206985]Your script is checking the DB with variables that don't exist so it's returning 0 rows, thus creating the error... You need to add a if($_POST) condition before the error checking so it will only error check if the $_POST variables are set....[/quote]Im new to php could someone show me how to do this with my script Link to comment https://forums.phpfreaks.com/topic/36417-solved-login-help/#findComment-173271 Share on other sites More sharing options...
corbin Posted January 31, 2007 Share Posted January 31, 2007 [code] if($_POST) { $query = "select * from user where username ='".$_POST[username]."' and password='".$_POST[password]."'"; $result = mysql_query($query); $total = mysql_num_rows($result); if($total < 1) { $login=error; } else { if(isset($UsErId)) { setcookie("UsErId","","0","/"); $UsErId=""; } $row = mysql_fetch_array($result); setcookie("UsErId",$row[id],"0","/"); $mydate = date("Y-m-d"); $update_user = "update user set login = '$mydate',login_status = 'Online!' where id = '$row[id]' and status = 'ACTIVE'"; $update_result = mysql_query($update_user); header("Location:index.php?ch=i"); } }[/code]Surely you can figure out where to put that... Link to comment https://forums.phpfreaks.com/topic/36417-solved-login-help/#findComment-173285 Share on other sites More sharing options...
steviez Posted January 31, 2007 Author Share Posted January 31, 2007 Thank you! works a treat Link to comment https://forums.phpfreaks.com/topic/36417-solved-login-help/#findComment-173293 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.