Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8321013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:52:17+00:00 2026-06-08T22:52:17+00:00

I’m trying to get a drop-down box to populate from data within a database,

  • 0

I’m trying to get a drop-down box to populate from data within a database, but it does not seem to be working. It passes an error saying that there is no data in the database for it to read but there is. Below is the script I used to make it work.

    <?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)) {
     if (is_file('admin/mysqli_connect.php')) { echo '<p>The connection file is there.</p>';require('admin/mysqli_connect.php'); }

else {
  echo '<p>The connection file is not there</p>';
  }
     $q="INSERT INTO Users (firstname, lastname, username, password1, birthdate, gamespyid, base) VALUES ('$firstname', '$lastname', '$username', md5('$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="http://www.virtual-aviation.org/gatewayaviation/index.php?p=register" 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>
       <td>Base:</td>
      <tr>
       <td><select name="base" size="1">
          <option>
            Select One
          </option>
         <?php
         $qf = "SELECT  airport_id, CONCAT_WS(' ', airport_name, airport_code) FROM airports ORDER BY airport_code ASC";
         $rf = mysqli_query ($dbc, $qf);

         if (mysqli_num_rows($rf) > 0) {
         while ($row = mysql_fetch_array ($rf, 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_close($dbc);

         ?>
        </select></td>
      </tr>
    </table>
   <input type='submit' name='submit' value='Register'/>
  </form>
  <?php
  echo '<p>debugger<p>' . $rf ;
  ?>
</body>
</html>

Here are some errors I get when I view the source code; the errors appear where the option box content should be.

Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /home5/virtua15/public_html/gatewayaviation/pages/register.inc.php on line 182

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in /home5/virtua15/public_html/gatewayaviation/pages/register.inc.php on line 184

Please a new airport first.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T22:52:19+00:00Added an answer on June 8, 2026 at 10:52 pm

    Either use mysql_* or mysqli_* functions, but you can’t use both. I’d prefer you choose the latter and learn about prepared statements: http://php.net/manual/en/mysqli.quickstart.prepared-statements.php

    The problem is your $dbc variable is most likely a mysql resource or null, not a mysqli resource so when you pass it to the mysqli_* functions it fails. There are ways to check and ensure you have a valid resource:

    $mysqli = new mysqli("example.com", "user", "password", "database");
    if ($mysqli->connect_errno) {
        echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
    }
    

    To solve your problem, you need to restructure your code to use only mysqli and make sure $dbc is a valid mysqli resource.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Does anyone know how can I replace this 2 symbol below from the string
I want to construct a data frame in an Rcpp function, but when I
I have a view passing on information from a database: def serve_article(request, id): served_article
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.