簡體   English   中英

注冊表未提交,下拉框未填充

[英]Registration form not submitting and drop down box not populating

我正在為我的網站編寫注冊表。

注冊表格上的一個字段是一個下拉框,該框由MySQL數據庫上的表格填充。

我最初以不同的方式編寫了注冊腳本,但是我需要更改表單的工作方式以適應新的下拉框及其收集數據的方式。

在進行更改之前,已成功提交了表單,但現在它給了我白屏。

我已經用if-else語句檢查了mysqli_connect.php。 它表明它正在運行,但是當按下“提交”按鈕時,沒有注冊被發送到MySQL服務器。 另外,下拉框未顯示鏈接到的MySQL表中的任何內容。

以下是我正在使用的腳本的副本:

<?php
@ini_set('display_errors', 'on');
echo "<h1>Register</h1>";

if ($_SERVER['REQUEST_METHOD'] == 'POST'){
  $errors = array();
  if (empty($_POST['firstname'])){
    $errors[] = 'Your forgot to enter your first name.';
  }else{
    $firstname = trim($_POST['firstname']);
  }
  if (empty($_POST['lastname'])){
    $errors[] = 'Your forgot to enter your last name.';
  }else{
    $lastname = trim($_POST['lastname']);
  }
  if (empty($_POST['username'])){
    $errors[] = 'Your forgot to enter your  username.';
  }else{
    $username = trim($_POST['username']);
  }
  if (!empty($_POST['password1'])) {
    if ($_POST['password1'] != $_POST ['password2']) {
      $errors[] = 'Your password did not match the confirmed password!';
    }else{
      $password = trim($_POST['password1']);
    }
  } else {
    $errors[] = 'You forgot to enter your password!';
  }
  if (empty($_POST['birthdate'])){
    $errors[] = 'Your forgot to enter your  birthdate.';
  }else{
    $birthdate = trim($_POST['birthdate']);
  }
  if (empty($_POST['gamespyid'])){
    $errors[] = 'Your forgot to enter your  gamespy id.';
  }else{
    $gamespyid = trim($_POST['gamespyid']);
  }
  if (empty($errors)) {
    require ('mysqli_connect.php');
    $q="INSERT INTO Users (firstname, lastname, username, password1, birthdate, gamespyid, base) VALUES ('$firstname', '$lastname', '$username', SHA1('$password1'), '$birthdate', '$gamespyid', '$base')";
    $r = @mysql_query($dbc, $q);
    if ($r){
      echo'<p>You are now registered</p>';
    }else{
      echo'<p>You have not been registered</p>';
    }
  } else {
    echo 'Error<br> <p>The following errors have occured:<br/>';
    foreach ($error as $msg) {
      echo " - $msg<br/>\n";
    }
    echo '</p><p>Please try again.</p><p><br/></p>';
  }   //if no errors
}     //submit
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
  <title></title>
</head>

<body>
  <form action="../pages/register.inc.php" method='POST'>
    <table summary="REgform">
      <tr>
        <td>First Name:</td>

        <td><input type='text' name='firstname' value='<?php echo $firstname; ?>'></td>
      </tr>

      <tr>
        <td>Last Name:</td>

        <td><input type='text' name='lastname'value='<?php echo $lastname; ?>'></td>
      </tr>

      <tr>
        <td>Username:</td>

        <td><input type='text' name='username'value='<?php echo $username; ?>'></td>
      </tr>

      <tr>
        <td>Password:</td>

        <td><input type='password' name='password1'></td>
      </tr>

      <tr>
        <td>Repeat Password:</td>

        <td><input type='password' name='password2'></td>
      </tr>

      <tr>
        <td>Birthdate:</td>

        <td><input type='text  ' name='birthdate'value='<?php echo $birthdate; ?>'></td>
      </tr>

      <tr>
        <td>Gamespy Id:</td>

        <td><input type='text' name='gamespyid'value='<?php echo $gamespyid; ?>'></td>
      </tr>

      <tr>
        <td>Base:</td>

       <td><select name="base" size="1">
          <option>
            Select One
          </option>
         <?php  require('http://www.virtual-aviation.org/gatewayaviation/admin/mysqli_connect.php');
         $q = "SELECT  id, CONCAT_WS(' ', airport_name, airport_code) FROM airports ORDER BY airport_code ASC";
         $r = mysqli_query ($dbc, $q);
         if (mysqli_num_rows($r) > 0) {
         while ($row = mysql_fetch_array ($r, MYSQL_NUM)) {
         echo "<option value=\"$row[0]\"";
         if (isset($_POST['existing']) && ($_POST['existing'] == $row[0]) ) echo 'selected="selected"'; echo ">$row[1]</option>\n";
         }
   } else {
   echo '<option>Please a new airport first.</optioon>';
    }
    mysqli_close($dbc);
         ?>
        </select></td>
      </tr>
    </table>

    <p><input type='submit' name='submit' value='Register'></p>
  </form>
</body>
</html>

在下拉框區域中發現的錯誤警告 :mysqli_query()期望參數1為mysqli,在第178行的/home5/virtua15/public_html/gatewayaviation/pages/register.inc.php中給出的null

警告 :mysqli_num_rows()期望參數1為mysqli_result,在第180行的/home5/virtua15/public_html/gatewayaviation/pages/register.inc.php中給出的null
請先去一個新機場。

您不能從“ http”中要求。 你需要改變

require('http://www.virtual-aviation.org/gatewayaviation/admin/mysqli_connect.php');

到一些本地路徑

require('mysqli_connect.php');

恕我直言,首先通過回顯檢查您的mysql查詢,然后通過編輯器運行查詢。

其次,盡管您設置了display_errors,但仍然可能無法查看錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM