无法使用回车键提交表单

时间:2015-08-26 01:25:53

标签: html submit

我讨厌提交这个问题,但我现在已经找不到解决方案近一周了。

  <div class="scanform">
  <form action="scanform.php" method="post" id="scanform">
  <p> <label for="Order Number">Order Number:</label>
  <input name="OrderNumber" id="OrderNumber" autofocus="" type="text"><span class="error">*<?php echo $ONErr;?>
  </span></p>
  <input name="submit" value="Submit" type="submit"></form>
  </div>

单击提交按钮时表单效果很好,但是如果我在文本字段中输入并按回车键,表单就会重新加载。

我无法弄清楚我做错了什么。

PHP代码:

<?php date_default_timezone_set('America/Toronto');

$ONErr = "";
if (isset($_POST['submit']))
{

  $link = mysqli_connect("localhost", "username", "password", "ordertracking");
  if($link === false){
    die("ERROR: Could not connect. " . mysqli_connect_error());
  }
  // Escape user inputs for security
  if (empty($_POST['OrderNumber'])) {
    $ONErr = "OrderNumber is required";
  } else {
    $OrderNumber = mysqli_real_escape_string($link, $_POST['OrderNumber']);
    // Attempt insert query execution
    $query = "SELECT * FROM Orders WHERE OrderNumber LIKE '%$OrderNumber' ORDER BY TimeStamp DESC LIMIT 1";
    $result = mysqli_query($link, $query) or trigger_error("Query Failed! SQL: $query - Error: ". mysqli_error($mysqli), E_USER_ERROR);
  } 
  // Close connection
  mysqli_close($link);
}

?>

0 个答案:

没有答案