I know this is really a HTML question rather than a php question (i think, anyway) - but I need to apply it in a php situation 😃

I've got a simple username and password field, and I want whoever is using it to be able to type in their username and password, then just hit enter rather than having to click submit. Currently when they hit enter, for some reason it just goes back to the previous page.

Cheers,

    Could you place a small snipit of code that your using for the form on here? That would help. Also, I think the enter button for the form is going to work a little different in Netscape than IE. Can't remember for sure.

      html>
      <head><title>Current Profile Users</title></head>
      <body>
      <?
      include("config.php"); //calls sql_connect(), sql_accessdb() & sql_submit1()
      
      if (isset($adduser)) {
      	PrintForm();
      	exit();
      }
      
      else {
      	sql_connect(); #config.php function
      	sql_accessdb(); #config.php function
      	if($submit == "SUBMIT") {
      		sql_submit1("profile","username","$name", "Your name was added to the database successfully.");
      		$submit = NULL;
      		print "<a href=\"$PHP_SELF\"> <- Return to Main</a>";
      		exit();
      	}
      
      $names = @mysql_query("SELECT username FROM profile ORDER BY username");
      if(! $names) {
      	print "Error performing query: " . mysql_error();
      	exit();
      }
      
      while ($row = mysql_fetch_array($names)) {
      	print $row["username"] . "<BR>";
      }
      
      //add a name
      print "<a href=\"$PHP_SELF?adduser=1\">Add a name</a>";
      }
      
      function PrintForm() {
      ?>
      <form action="names.php" method="post">
        <table align=center>
          <tr> 
            <td><div align="right">Character Name:</div></td>
            <td><input type="text" name="name"></td>
            <td colspan="2"><div align="center"> 
            <input type="submit" name="submit" value="SUBMIT">
              </div></td>
          </tr>
        </table>
      </form>
      <?
      }
      
      function sql_submit1($table, $field, $data, $success) {
      	$sql = "INSERT INTO $table SET
      			$field='$data'";
      	if( @mysql_query($sql)) {
      		print $success;
      	}
      
      else {
      	print "Error submitting to database";
      }
      }
      ?>
      

      Theres the code for the page, the form function is near the bottom.

        I think it is a problem with the way the code interprets $adduser. If your globals are registered, then $adduser is set in both instances, therefore, when you submit the form; $adduser is still set andthe code is not making it to the next step.

        Try adding a second confirmation step to your if:

        if (isset($adduser) && !isset($submit)) {
        PrintForm();
        exit();
        }

          Write a Reply...