Jump to content

Php Form [Solved]


Bob_

Recommended Posts

I'm trying to get a drop down menu to work, but I can't seem to get it to work at all. Its got to be in the <?php ?> code as its to get values dynamically.

The list is going to be filled with 2 fields from a MySQL database. The Name field is going to be the text shown in the drop down menu, the value is going to be the value from ID colum in the database.

[code]
<?php
$result = mysql_query("SELECT * FROM client")
or die(mysql_error()); 



echo '<form name="form1" method="post" action="">';
echo '<select name="select">';
//make some short variables
$ID=$row['ID'];//suppy the correct field names below
$Name=$row['Name'];
while($row = mysql_fetch_array( $result )) {
echo '<option value="' . $ID . '">' . $Name . '</option>';
}
echo "</select>";
echo "</form>";

?>[/code]

Although the menu is filled with the correct number of blank entries, but the every option is a " and every value is ' ' Does anyone know what I'm doing wrong?
Link to comment
https://forums.phpfreaks.com/topic/14404-php-form-solved/
Share on other sites

$ID=$row['ID']; & $Name=$row['Name']; Needs to be within the loop to change the data.

[CODE]
<?php
$result = mysql_query("SELECT * FROM client")
or die(mysql_error()); 

echo '<form name="form1" method="post" action="">';
echo '<select name="select">';
//make some short variables
while($row = mysql_fetch_array( $result )) {

$ID=$row['ID'];//suppy the correct field names below
$Name=$row['Name'];


echo '<option value="' . $ID . '">' . $Name . '</option>';
}
echo "</select>";
echo "</form>";

?>
[/CODE]
Link to comment
https://forums.phpfreaks.com/topic/14404-php-form-solved/#findComment-56899
Share on other sites

What version of PHP are you running? Did you insert the lines exactly as I showed?

If the version of PHP is less than 4.3.0, you would need:
[code]<?php
echo '<pre>';
echo '$_GET: ';
print_r ($_GET);
echo '$_POST: ';
print_r($_POST);
echo '</pre>';
?>[/code]

Ken
Link to comment
https://forums.phpfreaks.com/topic/14404-php-form-solved/#findComment-57388
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.