...

View Full Version : PHP Output Problem



BrandonSi
06-20-2006, 10:38 PM
I'm trying to get a simple php script to populate a dropdown box.. the php code works as a standalone .php, but when I add it to the HTML file with some other forms and view the page, it fails.. So the code is solid, I think it must be a problem with the echo statements?! I don't even get the dropdown box! Any suggestions?



<form action="handle.php" action="POST">
<input type="text" name="amount">amount
<input type="text" name="category">category
<input type="text" name="description">description

<?
$dbh=mysql_connect ("localhost", "branthan_et", "password") or die ('I cannot connect to the database because: ' . mysql_error());

mysql_select_db ("branthan_expensetracker");

$sqlOptions = "SELECT * from categories";

$resultOptions = mysql_query($sqlOptions);


echo '<select name="selectName">';

echo '<option value="">--Select--</option>';

while($opt = mysql_fetch_array($resultOptions))
{
echo '<option value="'.$opt['categories'].'">'.$opt['categories'].'</option>';
}

echo '</select>';
?>


<input type="text" name="payment">payment
<input type="text" name="amount">amount
<input type="text" name="date">date
</form>

lavinpj1
06-20-2006, 10:41 PM
Do you get any errors?

~Phil~

BrandonSi
06-20-2006, 10:45 PM
Nope, no errors.. I'll post the output..



amount category description '; echo '--Select--'; while($opt = mysql_fetch_array($resultOptions)) { echo ''.$opt['categories'].''; } echo ''; ?> payment amount date


The drop-down box should be after description, so the output of what should be the dropdown box is

'; echo '--Select--'; while($opt = mysql_fetch_array($resultOptions)) { echo ''.$opt['categories'].''; } echo ''; ?>

Fumigator
06-20-2006, 11:45 PM
What is the source code of the page after it's built (from the browser)?

BrandonSi
06-20-2006, 11:52 PM
What is the source code of the page after it's built (from the browser)?

Well here's the updated code.. no echo errors, but now nothing is listed in the dropdown box.

<form action="handle.php" action="POST">
<input type="text" name="amount">amount
<input type="text" name="category">category
<input type="text" name="description">description

<select name="selectName">


<?php


$dbh=mysql_connect ("localhost", "branthan_et", "password") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("branthan_expensetracker");

$sqlOptions = "SELECT * FROM categories";
$resultOptions = mysql_query($sqlOptions);

while($opt = mysql_fetch_assoc($resultOptions))
{
echo "<option value=\"".$opt['categories']."\"></option>";
}

?>
</select>
</form>


Actually the source for the page is the same as what I posted.. I didn't think it should be showing the php code?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum