Jump to content

enter wont submit form


aebstract

Recommended Posts

<?php
if(isset($_SESSION["id"]))
{
  header("Location: /accounthome/");
  exit();
}

//Doesn't this happen in the include('connect.php') in index.php?
mysql_connect("localhost","berryequipment","gU8Kso8Y") or die(mysql_error());
mysql_select_db("berryequipment_net_db");

if(isset($_POST['submit']))
{
  if(empty($_POST['password']))
  {
    $error .= 'You must fill in a password <br />';
  }
  if(!strlen($error))
  {
    $result = mysql_query("SELECT * FROM `users` WHERE `plant` = '".mysql_real_escape_string($_POST['dropdown'])."' AND `password` = '".md5($_POST['password'])."'")
      or die("Query error: ".mysql_error());
    if(mysql_num_rows($result) == 0)
    {
      $error .= "The pasword you entered did not match the plant location you chose.";
    }
    else
    {
      $worked = mysql_fetch_array($result);
      $_SESSION["id"] = $worked['plant'];

      header("Location: /accounthome/");
      exit;
    }
  }
}

$content .= '<center><table><tr><td><form action="/login/" method="post">Location: </td><td><select name="dropdown">';
$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></td></tr><tr><td>
Password:
</td><td>
<input type="password" name="password" size="6" />
</td></tr><tr><td></td><td>
<input type="submit" name="submit" value="login" />
</td></tr></table></center></form>';
?>

 

Okay, here is the problem I am having:

If you're on internet explorer and fill out your password and hit enter, it just reloads the page.. Firefox will submit the form and log you in. Is this a problem with the php, just the form or something else? I am not sure and it is a problem because a lot of people like to just push enter after inserting their passwords! Please help, and thank you.

Link to comment
https://forums.phpfreaks.com/topic/96892-enter-wont-submit-form/
Share on other sites

if(isset($_POST['submit']))

 

To make enter work, remove that line of code. That line means "if the button 'submit' is pressed, continue" pressing enter is not pressing that button  ;).

 

No, that's not true. $_POST['submit'] is simply present if the form has been submitted, no matter how it was done.

 

To OP: I see you use a lot of javascript for the site, does any of it apply to the form? If not, test your form starting from scratch, and see if it works. Then add on code as long as it's still working, and you'll eventually find the error.

No, that's not true. $_POST['submit'] is simply present if the form has been submitted, no matter how it was done.

 

No, THAT is incorrect. If you have no form element with name='submit', $_POST['submit'] will be empty. try this:

 

<?
      $username = "user"; 
      $password = "password";

   if ($_POST['submit']) {
   	die ("form was posted");
   	
}
   ?>
   
   <h4>Login Below:</h4> 
         
   <div class="detailTextGrey">
   
   <!-- Login Form -->
   <form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">          
   User Name: <input type="text" name="loginUserName"> 

   Password: <input type="password" name="loginPassword"> 
   <input type="submit" value="test" name='test'>
   </form>

 

to be certain that a form was submitted either check $_SERVER['REQUEST_METHOD'] or look for a specific $_POST value. I prefer to go straightforward with $_SERVER['REQUEST_METHOD']

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.