aebstract Posted January 18, 2008 Share Posted January 18, 2008 Trying to a get login function to work. I have gone through several areas of the code to try and limit the problem to one specific area. I'm passing up the password fine, but I think the 'id' from the database isn't getting passed up from the drop down. I put an echo in the top to display the id and when I hit submit, nothing displays. ??? the code: <select name="dropdown">'; mysql_connect("localhost","berryequipment","gU8Kso8Y") or die(mysql_error()); mysql_select_db("berryequipment_net"); $result = mysql_query("SELECT * FROM plants ORDER BY plantloc ASC") or DIE(mysql_error()); $allplants = mysql_num_rows($result); while ($r=mysql_fetch_array($result)) { $id=$r["id"]; $plantloc=$r["plantloc"]; for ($op = 1; $op <= $allplants; $op++) { $content .= "<option value=\"$id\">$plantloc</option>\n"; } } $content .= '</select> Quote Link to comment https://forums.phpfreaks.com/topic/86635-solved-login-script-issue/ Share on other sites More sharing options...
aebstract Posted January 18, 2008 Author Share Posted January 18, 2008 Update: I took out the 'for loop', it wasn't necessary and it was displaying multiples of each option. Now the drop down is displaying one of each row from the database. Quote Link to comment https://forums.phpfreaks.com/topic/86635-solved-login-script-issue/#findComment-442706 Share on other sites More sharing options...
monkeytooth Posted January 18, 2008 Share Posted January 18, 2008 You still having an issue or is this solved? Quote Link to comment https://forums.phpfreaks.com/topic/86635-solved-login-script-issue/#findComment-442708 Share on other sites More sharing options...
aebstract Posted January 18, 2008 Author Share Posted January 18, 2008 Still has an issue with logging in, was just putting an update on how it is displaying the drop down in case someone wanted to point the for loop as an issue. Here is the code that is trying to connect and match up the variable, maybe it will help out: $result = mysql_query("SELECT id, plantloc, password, address FROM plants WHERE id=('$_POST[id]') AND password=('".md5($_POST['password'])."')") or die ("error"); if (mysql_num_rows($result) == 0) { $echo = 'The pasword you entered did not match the plant location you chose. <br />'; } else { $worked = mysql_fetch_array($result); $_SESSION["id"] = $worked[id]; header("Location: acchome.php"); } Quote Link to comment https://forums.phpfreaks.com/topic/86635-solved-login-script-issue/#findComment-442709 Share on other sites More sharing options...
revraz Posted January 18, 2008 Share Posted January 18, 2008 You are not reporting your error right. First thing, add a mysql_error after your query so you know if your query is wrong. Second, change $echo = 'The pasword you entered did not match the plant location you chose. <br />'; to echo 'The pasword you entered did not match the plant location you chose. <br />'; Quote Link to comment https://forums.phpfreaks.com/topic/86635-solved-login-script-issue/#findComment-442765 Share on other sites More sharing options...
aebstract Posted January 18, 2008 Author Share Posted January 18, 2008 I have been working around looking for the problem still and have come to a more solid conclusion that the id variable isn't being passed from that drop down to my other part of the script. I changed the error coding like you said, and it IS displaying the error of "password doesn't match". Which proves that the ID isn't passing correctly even more. Quote Link to comment https://forums.phpfreaks.com/topic/86635-solved-login-script-issue/#findComment-442772 Share on other sites More sharing options...
revraz Posted January 18, 2008 Share Posted January 18, 2008 Echo it before the header $worked = mysql_fetch_array($result); echo $worked[id]; exit; header("Location: acchome.php"); You're using sessions, are you using session_start() at the top of both pages? Quote Link to comment https://forums.phpfreaks.com/topic/86635-solved-login-script-issue/#findComment-442776 Share on other sites More sharing options...
aebstract Posted January 18, 2008 Author Share Posted January 18, 2008 It's all in one file, account.php. The form redirects back to the same page and if submit is hit that is when the top part goes in to play. I'll post all the php coding below so you can see. I have tried to echo out the id from the selection but it doesn't seem to be displaying a single thing. I really think the id isn't getting passed. <?php session_start(); header("Cache-control: private"); if(isset($_SESSION["id"])) { header("Location: acchome.php"); } if(!isset($_SESSION["id"])) { if (isset ($_POST['submit'])) { $problem = FALSE; if (empty ($_POST['password'])) { $problem = TRUE; $error .= 'You must fill in a password <br />'; } $echoedid = $_POST['id']; echo "$echoedid"; if (!$problem) { mysql_connect("localhost","berryequipment","gU8Kso8Y") or die(mysql_error()); mysql_select_db("berryequipment_net"); $result = mysql_query("SELECT id, plantloc, password, address FROM plants WHERE id=('$_POST[id]') AND password=('".md5($_POST['password'])."')") or die ("error"); if (mysql_num_rows($result) == 0) { echo 'The pasword you entered did not match the plant location you chose.'; } else { $worked = mysql_fetch_array($result); $_SESSION["id"] = $worked[id]; header("Location: acchome.php"); } } } } ?> and the form area <?php echo "$error"; $content .= ' <form action="account.php" method="post"> plant loc<br /> <select name="dropdown">'; mysql_connect("localhost","berryequipment","gU8Kso8Y") or die(mysql_error()); mysql_select_db("berryequipment_net"); $result = mysql_query("SELECT * FROM plants ORDER BY plantloc ASC") or DIE(mysql_error()); while ($r=mysql_fetch_array($result)) { $id=$r["id"]; $plantloc=$r["plantloc"]; $content .= "<option value=\"$id\">$plantloc</option>\n"; } $content .= '</select> <br /><br /> password <br /> <input type="password" maxlength="6" class="textfield" name="password" value="' . $_POST[password] . '" size="6" /><br /><br /> <input type="submit" name="submit" class="textfield" value="login" /> </form>'; echo "$content"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/86635-solved-login-script-issue/#findComment-442801 Share on other sites More sharing options...
aebstract Posted January 18, 2008 Author Share Posted January 18, 2008 Hopefully this bit of information might help as well: <select name="dropdown"><option value="18">Pilgrim's Pride - </option> <option value="16">Tyson Foods - A</option> <option value="1">Tyson Foods - Clarksville, AR</option> <option value="17">Tyson Foods - G</option> </select> This was when I went to the page and click view > page source to see if the id was actually inserting in to the value. It is, so I am not grabbing it correctly somehow? Quote Link to comment https://forums.phpfreaks.com/topic/86635-solved-login-script-issue/#findComment-442823 Share on other sites More sharing options...
revraz Posted January 18, 2008 Share Posted January 18, 2008 Assuming this is where you want to grab the ID from the dropdown $echoedid = $_POST['id']; it should be $echoedid = $_POST['dropdown']; Otherwise, I don't see where you post "id". Quote Link to comment https://forums.phpfreaks.com/topic/86635-solved-login-script-issue/#findComment-442828 Share on other sites More sharing options...
aebstract Posted January 18, 2008 Author Share Posted January 18, 2008 woo, that's what I was doing wrong. I have never really used a drop down and didn't know how to grab the value. Thank You! Quote Link to comment https://forums.phpfreaks.com/topic/86635-solved-login-script-issue/#findComment-442834 Share on other sites More sharing options...
revraz Posted January 18, 2008 Share Posted January 18, 2008 No problem. Quote Link to comment https://forums.phpfreaks.com/topic/86635-solved-login-script-issue/#findComment-442836 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.