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

  • SEARCH
  • Home
  • 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 1079671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:54:24+00:00 2026-05-16T21:54:24+00:00

I am using PHP 5 to create a query page for a MySQL database

  • 0

I am using PHP 5 to create a query page for a MySQL database with 2 tables “students” and “teachers”. I have created a combo box which can allow users to view and select the 2 tables from the combo box via a “submit” button after selecting from the combo box.

However the problem with the script is that I want to verify if the “submit” button works which I created a “echo.php” to echo out the value of the combo box and submit button. Overall the idea is to do a query like these steps:

1) User selects value from combo box “teacher” or “student”.
2) User clicks submit button.
3) After clicking submit button, user is redirected to “echo.php”
4) “echo.php” should output/echo out either “teacher” or “student”.

The codes for script:

<?php
include "db_connect.php";
{
?>
<td valign=top><strong>Name:</strong></td>
<td>

<?php
echo "<form name = \"queryEquipTypeForm\" method = \"post\" action
=\"select_table.php\">"; 
echo '<select name=\"table\">'; 
echo "<option size =30 selected>Select</option>";

$result = mysql_query("show tables");

if(!$result) trigger_error("Query Failed: ".  mysql_error($db), E_USER_ERROR);

if(mysql_num_rows($result)) 
{ 
while($table_array = mysql_fetch_array($result)) 
{ 
    echo "<option>$table_array[0]</option>";
}    

echo '</select>';

echo '</form>';

if(!$_POST['submit'])
{
?>
<form method="post" action="select_table.php">   
<input type="submit" name="submit" value="Submit">
</form>
<?php
}
else
{
  echo '<script type="text/javascript">
        alert("Redirecting you to echo.php page");
        window.location="echo.php"</script>';
}

} 
else 
{
echo "<option>No Names Present</option>";  
} 
}

?>
</td>

The codes for “echo.php” :

<?php
include "select_table.php";
echo "data is : ".$_POST['table'];
?>

The output of echo.php would be exactly the same as “select_table.php” with the cobo box and the “data is: ” without the “teachers” or “student” word as its being redirected to echo.php.

  • 1 1 Answer
  • 1 View
  • 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-05-16T21:54:24+00:00Added an answer on May 16, 2026 at 9:54 pm

    I’m not quite sure what exactly what you want to do, but as michaeltwofish already pointed out, redirecting to another page using javascript will make you lose the post data. Also you seem to echo two <form> elements when the select_table.php is called without post data, one with only a submit button, while your first form is missing the button.

    Normally, you would want your php script to either output the form with the combobox where the user can select the table, or, if there was post data (meaning that the user selected a value), the results of the selection, kinda like the following:

    <?php
    
    if(isset($_POST['table'])) {
        print "Selected element: " . $_POST['table'];
    } else {
        echo '<form method="post" action="select_table.php">';
        echo '<select name="table">';
        // here should be your SQL query and the combobox options generation
        echo '</select>';
        echo '<input type="submit" />';
        echo '</form>';
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have started programming for sometime with PHP using MySQL as the database and
I want to create JSON object using tow query in PHP , Then retrieve
How do I create dynamic images using php which depend of $_GET['x'] variables?
I am using PDO with PHP to create a new database and then a
I'm creating an events website using PHP. I have a database with an events
I create a table using PHP from a database, meaning the size of the
Learning php! I have a sql database which contains a table called 'images' which
I have a php file which connects to a MySql db and read the
I'm building a jQuery Mobile site, using PHP to interact with a MySQL database
I have already created a report using list of data from my database. i

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.