Ok
I have this database with some contact names of people. I am trying to make a form that will take those names from the database and put it into a drop down menu. I have the script here:
<?php
$db = mysql_connect("localhost", "root", "***");
mysql_select_db("xc_contact",$db);
$sql="SELECT FirstName,LastName,contact_id FROM `names`";
$result=mysql_query($sql,$db);
while($row=mysql_fetch_array($result))
{
$FirstName = $row["FirstName"];
?>
<form method="POST" action="www.marker5a.com/database/logger2.php">
<p><select size="1" name="menu">
<option><?php echo $FirstName; ?></option>
</select><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>
I am new at Php, so I am not sure if this is correct. I keep getting a parse error. The link is http://www.marker5a.com/database/logger.php
I appreciate all of the help I can get. Thank you
Chris
parse error with drop down menu
Moderator: General Moderators
I think it may have something to do with a missing brace on your while loop. But the main problem is that you're only going to get one option in your select box, the last one in the list.
The following builds the option list first, then drops it into the HTML...
The following builds the option list first, then drops it into the HTML...
Code: Select all
<?php
$db = mysql_connect("localhost", "root", "***");
mysql_select_db("xc_contact",$db);
$sql = "SELECT FirstName, LastName, contact_id FROM `names`";
$result = mysql_query($sql, $db);
while ($row = mysql_fetch_array($result)) {
$options .= '<option>'.$row["FirstName"].'</option>';
}
echo '<form method="POST" action="www.marker5a.com/database/logger2.php"><p><select size="1" name="menu">';
echo $options;
echo '</select><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p></form>';
?>-
malcolmboston
- DevNet Resident
- Posts: 1826
- Joined: Tue Nov 18, 2003 1:09 pm
- Location: Middlesbrough, UK
first of all im gonna clean up your code formatting
try this
for your information reason you were getting parse errors is because you didnt have a }
Code: Select all
<?php
$db = mysql_connect("localhost", "root", "***");
mysql_select_db("xc_contact",$db);
$sql="SELECT FirstName,LastName,contact_id FROM `names`";
$result=mysql_query($sql,$db);
while($row=mysql_fetch_array($result))
{
$FirstName = $row["FirstName"];
?>
<form method="POST" action="www.marker5a.com/database/logger2.php">
<p><select size="1" name="menu">
<option><?php echo $FirstName; ?></option>
</select><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>Code: Select all
<?php
$db = mysql_connect("localhost", "root", "***");
mysql_select_db("xc_contact",$db);
$sql="SELECT FirstName,LastName,contact_id FROM `names`";
$result=mysql_query($sql,$db);
while($row=mysql_fetch_array($result))
{
$FirstName = $row["FirstName"];
print "
<form method="POST" action="www.marker5a.com/database/logger2.php">
<p><select size="1" name="menu">
<option>$FirstName</option>
</select><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>":
else
{
// error handler?
}-
magicrobotmonkey
- Forum Regular
- Posts: 888
- Joined: Sun Mar 21, 2004 1:09 pm
- Location: Cambridge, MA
err i think your logic is a little off as well:
Code: Select all
<?php
$db = mysql_connect("localhost", "root", "***");
mysql_select_db("xc_contact",$db);
$sql="SELECT FirstName,LastName,contact_id FROM `names`";
$result=mysql_query($sql,$db);
print "
<form method="POST" action="www.marker5a.com/database/logger2.php"> \n
<p><select size="1" name="menu">\n ";
while($row=mysql_fetch_array($result))
{
$FirstName = $row["FirstName"];
print "
<option>$FirstName</option>\n ";
}
print"
</select><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>":
else
{
// error handler?
}
?>