Jump to content

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/86635-solved-login-script-issue/
Share on other sites

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");
} 

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 />';

 

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.

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";



?>


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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.