Sarahc Posted February 24, 2007 Share Posted February 24, 2007 I am using the script below, but when I go to the next page it says I am not logged in, like it is not passing the login info. I posted the page that is saying I need to log in after the first script. <?php $login = $_REQUEST['login']; $password = $_REQUEST['password']; $sql = "select * from users where login = '$login' and password = '$password'"; $result = mysql_query($sql ,$db); if ($myrow = mysql_fetch_array($result)) { do { $uid = $myrow["userid"]; $uname = $myrow["login"]; } while ($myrow = mysql_fetch_array($result)); $loggedin = true; $upwd = $password; $msg = "Welcome $uname, you are now logged in. <a href=index.php>Click here</a> to return to the front page."; } else { $loggedin = false; $upwd = ""; $uid = ""; $uname = ""; $msg = "Sorry, that login and password is not valid. Click back on your browser to try sgain. If you have forgotten your password <a href=forgot.php>click here</a>. If you are a new user you will need to <a href=newuser.php>create a new login</a>"; } session_register("loggedin"); session_register("upwd"); session_register("uid"); session_register("uname"); ?> <?php include("theader.php"); ?> <TD align="left" valign="top" bgcolor="#F3E79E"> <table width="100%" border="0" cellspacing="5" cellpadding="5"> <tr> <td valign="top"> <TABLE width=100% cellpadding=5 cellspacing=0 border=0> <tr><td width=500 align=center> <table cellpadding=1 cellspacing=1 border=0><tr><td bgcolor=#000000 width=500 height=20 valign=center align=center> <table cellpadding=0 cellspacing=0 border=0><tr><td bgcolor="#CC6600" width=498 height=18 valign=center align=left> <font face="Arial, Helvetica, sans-serif" size="3"><b>Add a Recipe</b></font> </td></tr></table> </td></tr></table> </td></tr> <TR> <TD valign=top> <FONT SIZE=2> <center> <font size=2> <?php if (logincheck($uid, $upwd)) { ?> </font> <form enctype="multipart/form-data" action=saverecipe.php method=post> <input type="hidden" name="MAX_FILE_SIZE" value="200000"> <table cellpadding=5 cellspacing=0> <tr> <th colspan=2> <p> <label>If you are unsure, please do not select.</label> </p> <p> <label>Gluten Free <input type="radio" name="gluten" value="1"> yes</label> </p> <p> <label>Casein Free <input type="radio" name="casein" value="1"> yes</label> <label> </label> </p> <p> <label>Soy Free <input type="radio" name="soy" value="1"> yes</label> </p> <p> <label>Yeast Free <input type="radio" name="yeast" value="1"> yes</label> </p> <p> <label>Phenol Free <input type="radio" name="phenol" value="1"> yes</label> <br> </p><br> Enter the title for your Recipe</th> </tr> <tr> <td colspan=2 align=center><input type=text name=recipetitle size=60></td> </tr> <tr> <th colspan=2><font size=2 face='Arial, Helvetica, sans-serif'>Enter the Ingredients</font></th> </tr> <tr> <td><input type="text" name="ingred[]" size=30></td> <td><input type="text" name="ingred[]" size=30></td> </tr> <tr> <td><input type="text" name="ingred[]" size=30></td> <td><input type="text" name="ingred[]" size=30></td> </tr> <tr> <td><input type="text" name="ingred[]" size=30></td> <td><input type="text" name="ingred[]" size=30></td> </tr> <tr> <td><input type="text" name="ingred[]" size=30></td> <td><input type="text" name="ingred[]" size=30></td> </tr> <tr> <td><input type="text" name="ingred[]" size=30></td> <td><input type="text" name="ingred[]" size=30></td> </tr> <tr> <td><input type="text" name="ingred[]" size=30></td> <td><input type="text" name="ingred[]" size=30></td> </tr> <tr> <td><input type="text" name="ingred[]" size=30></td> <td><input type="text" name="ingred[]" size=30></td> </tr> <tr> <td><input type="text" name="ingred[]" size=30></td> <td><input type="text" name="ingred[]" size=30></td> </tr> <tr> <th colspan=2><font size=2 face='Arial, Helvetica, sans-serif'>Enter the cooking directions</font></th> </tr> <tr> <td colspan=2><textarea name=directions rows=20 cols=50></textarea> </tr> <tr> <th colspan=2>Upload recipe picture</th> </tr> <tr> <td colspan=2><input type=file name=frmpicture></td> </tr> <tr> <th colspan=2><font size=2 face='Arial, Helvetica, sans-serif'>Select a Categories</font></th> </tr> <tr><td colspan=2> <?php $sql = "select * from categories order by category"; $result = mysql_query($sql ,$db); $newrowcount = 0; printf("<table><tr>"); if ($myrow = mysql_fetch_array($result)) { do { if ($newrowcount == 4) { $newrowcount = 0; printf("</tr>"); printf("<tr>"); } printf("<td><font size=2 face='Arial, Helvetica, sans-serif'><input type=radio name=catid value=%s> %s</font></td>", $myrow["categoryid"], $myrow["category"]); $newrowcount++; } while ($myrow = mysql_fetch_array($result)); } for ($c = $newrowcount; $c < 4; $c++) { printf("<td></td>"); } printf("</tr></table>"); ?> </td></tr> <tr> <td colspan=2 align=middle> <br> <input type=reset value=Reset> <input type=submit value=Submit> </td> </tr> </table> </form> <?php } else { printf("<font size=2 face='Arial, Helvetica, sans-serif'><br>You need to be logged in before you can add a recipe</font>"); } ?> </center> </FONT> </TD> </TR> </TABLE> </td> </tr> </table> </TD> <?php include("tfooter.php"); ?> Link to comment https://forums.phpfreaks.com/topic/39879-what-am-i-doing-wrong-with-this-login/ Share on other sites More sharing options...
mmarif4u Posted February 24, 2007 Share Posted February 24, 2007 Where is ur session_start(); Link to comment https://forums.phpfreaks.com/topic/39879-what-am-i-doing-wrong-with-this-login/#findComment-192731 Share on other sites More sharing options...
papaface Posted February 24, 2007 Share Posted February 24, 2007 and use code tags! Link to comment https://forums.phpfreaks.com/topic/39879-what-am-i-doing-wrong-with-this-login/#findComment-192734 Share on other sites More sharing options...
magic2goodil Posted February 24, 2007 Share Posted February 24, 2007 Also you may think about mysql_fetch_assoc() instead of mysql_fetch_array(), assoc fetches a less cmplex array that can still be accessed with the keys you are using. Also, instead of: if ($myrow = mysql_fetch_array($result)) { do { $uid = $myrow["userid"]; $uname = $myrow["login"]; } while ($myrow = mysql_fetch_array($result)); } Perhaps think of something simpler in the future: if ($myrow = mysql_fetch_array($result)) { while ($myrow = mysql_fetch_array($result)) { $uid = $myrow["userid"]; $uname = $myrow["login"]; } } I just think the do() is unnecessary. Link to comment https://forums.phpfreaks.com/topic/39879-what-am-i-doing-wrong-with-this-login/#findComment-192736 Share on other sites More sharing options...
Sarahc Posted February 24, 2007 Author Share Posted February 24, 2007 None of these suggestions seem to help. Any more? Link to comment https://forums.phpfreaks.com/topic/39879-what-am-i-doing-wrong-with-this-login/#findComment-193101 Share on other sites More sharing options...
magic2goodil Posted February 24, 2007 Share Posted February 24, 2007 Instead of: if ($myrow = mysql_fetch_array($result)) { do { $uid = $myrow["userid"]; $uname = $myrow["login"]; } while ($myrow = mysql_fetch_array($result)); $loggedin = true; $upwd = $password; $msg = "Welcome $uname, you are now logged in. <a href=index.php>Click here[/url] to return to the front page."; } Try this: $myrow = mysql_fetch_assoc($result) or die(mysql_error()); $affected_rows = mysql_num_rows($result) or die(mysql_error()); if ($affected_rows == 1) { $uid = $myrow["userid"]; $uname = $myrow["login"]; $loggedin = true; $upwd = $password; $msg = "Welcome $uname, you are now logged in. <a href=index.php>Click here[/url] to return to the front page."; session_register("loggedin"); session_register("upwd"); session_register("uid"); session_register("uname"); } Link to comment https://forums.phpfreaks.com/topic/39879-what-am-i-doing-wrong-with-this-login/#findComment-193110 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.