views:

23

answers:

3

Hi There! I am currently using PHP 5 with a MysSQL database with 2 tables. So far my PHP Combo Box is working however I need to access the values selected from the combo box. it goes like this:

1) I select a value from the Combo Box. 2) I click on the Submit button 3) The Submit button brings me to another webpage.

The problem that my program is facing now is during step 3 when I click the submit button there is no webpage generated. I think the problem is due to the sequencing of the Combo Box Codes and Button Codes.

My codes are as shown:

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

<?php
echo '<select name="table_choice">'; 
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>";
}  

$array_value = $_POST['table_choice'];

if(!$_POST['submit'])
{
?>

<input type="submit" name="submit" value="Submit">

<?php
 }
 else
{
  echo '<script type="text/javascript">
        alert("Redirecting you to the site main page");
        window.location="echo.php"</script>';
 }

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

?>

Everything seems fine to me. Can someone please help or give tips? Thanks!

A: 
<?php
include "db_connect.php";
{
?>

what's with the random bracket?

Ross
erm....its to link to the second <?php ?? This is due to the database connection being stored on another php page. This way I don't have to manually try to connect to the database everytime i need a query.
JavaNoob
sorry i meant the "{" - looks randomly placed to me.
Ross
+1  A: 

Where is the <form> tag?

Anyway, consider writing your web applications using some web framework or at least templates to separate the program logic (PHP code) from the presentation (HTML code). Else it will be a big unmaintainable mess soon (or maybe it already is).

Juliusz Gonera
Why do you need the form tag?.... The button appears on the webpage though?.... [EDIT] Just added to "input" does not work.
JavaNoob
What do you exactly expect the submit button to do without a form tag with an action attribute? What did you add to "input"?
Juliusz Gonera
A: 

Never Mind got the answer. The answer is just to simply add an echo '</select>' above the $array_value = $_POST['table_choice'];. The answer is simply to end select with /select. Thanks for the extra tips guys.

JavaNoob