0

我正在尝试设计一个带有下拉框的注册页面。这需要 2 个数据库连接,一个在点击注册按钮时将数据发送到数据库,另一个从数据库中提取信息以填充下拉框。直到几天前,当我上传了一个与其他文件无关的文件时,我让这个脚本完美无缺,除了一个 require 语句来获取 config.inc.php (用于数据库连接和错误处理目的。)这个文件是几乎在我所有的脚本中都使用过,并且在我的网站中除了少数脚本之外的所有脚本都可以正常工作。上传此文件后,我的注册脚本部分填充下拉框不再起作用。

下面是有问题的脚本(我省略了数据验证和大部分 html 部分,如果需要,我可以重新添加它们。)

<?php
require_once('includes/config.inc.php');
$page_title = 'Register';


if ($_SERVER['REQUEST_METHOD'] == 'POST') {


    require_once(MYSQL);
    $trimmed = array_map('trim', $_POST);

    $fn = $ln = $usr = $pw = $bd = $gs = $bs = FALSE;
//DATA VALIDATION  

//END DATA VALIDATION
if($fn && $ln && $usr && $e && $pw && $bd && $gs && $bs) {
  $q = "SELECT user_id FROM Users WHERE email='$e'";
  $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br/>MySQL Error: " . mysqli_error($dbc));
  if (mysqli_num_rows($r) == 0) {
    $a = md5(uniqid(rand(), true));
    $q = "INSERT INTO Users (first_name, last_name, user_name, email, password1, birthdate, gamespy_id, base, active, registration_date)      VALUES ('$fn', '$ln', '$usr', '$e', SHA1('$pw'), '$bd', '$gs', '$bs', '$a', NOW() )";
    $r = mysqli_query($dbc, $q) or trigger_error("Query: $q\n <br/>MySQL Error:" . mysqli_error($dbc));
    if  (mysqli_affected_rows($dbc) == 1){
      $body = "Thank you for registering with Gateway Aviation. To activate your account, please click on this link:\n\n";
      $body .= BASE_URL . 'activate.php?x=' . urlencode($e) . "&y=$a";
      mail($trimmed['email'],'Registration Confirmation', $body, 'From: noreply@virtual-aviation.org');
      echo '<h3> Thank you for registering! A&nbsp;confirmation email has been sent to your address. Please click on the link in that email in order to activeate your accout.</h3>';
exit();
    } else {
      echo '<p class="error>You could not be registered due to a system error. We apologize for any inconvenience.</p>';
    }
  } else {
    echo '<p class="error"> That email has already been registered. If you have forgotten your password, use the link to reset it.</p>';
  }
  } else {
    echo '<p class="error">Please try again</p>';
  }


}
?>


        <td><input type='text' name='gamespyid' value='<?php if(isset($trimmed['gamespyid'])) echo $trimmed['gamespyid'];?>'/></td>
      </tr>
       <td>Base:</td>
       <td><select name="base" size="1">
          <option>
            Select One
          </option>
<?php
require_once(MYSQL);
         $q = "SELECT  airport_id, CONCAT_WS(' ', airport_code,' - ' airport_name) FROM airports ORDER BY airport_code ASC";
         $r = mysqli_query ($dbc, $q);

         if (mysqli_num_rows($r) > 0) {
         while ($row = mysqli_fetch_array ($r, MYSQLI_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.</option>';
    }
   mysqli_free_result($result); 

         ?>
        </select></td>
    </table>
   <input type='submit' name='submit' value='Register'/>
  </form>
</body>
</html>

我也在我的错误日志中收到此错误 [20-Aug-2012 03:09:25] PHP 致命错误:无法重新声明 my_error_handler() (之前在 /home5/virtua15/public_html/gatewayaviation/includes/config.inc.php 中声明:36) 在第 56 行的 /home5/virtua15/public_html/gatewayaviation/includes/config.inc.php

4

2 回答 2

0

你应该有

require_once('includes/config.inc.php');
require_once(MYSQL);

但是为什么你需要配置和 MYSQL 两次?一旦对整个脚本足够了,如果您从它们开始,它将适用于任何IF语句。

于 2012-08-20T07:12:07.717 回答
0

利用

require_once('includes/config.inc.php');

在顶部并删除第二个require('includes/config.inc.php');实例。

保持连接打开,仅在脚本结束时关闭它。而是在使用从数据库中提取数据后处理结果mysqli_free_result($result);

于 2012-08-20T07:24:10.657 回答