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
Share on other sites

It's wrong in relation to some of your other tags:

 

Wrong way (kinda the way you are doing it):

<table><tr><td><form></td></tr></table></form>

 

Right way:

<form><table><tr><td></td></tr></table></form>

 

You know, tags mustn't overlap each other.

Link to comment
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.

Link to comment
Share on other sites

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']

Link to comment
Share on other sites

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.