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 the开发者_高级运维re 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.
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).
<?php
include "db_connect.php";
{
?>
what's with the random bracket?
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.
精彩评论