Jump to content

filling a drop down select box from MYSQL table


stonebergftw

Recommended Posts

Is there any way to fill a <select> box with entries from a mysql table, and then to have the entries POST to fill in another mysql table.

 

Example.

 

MYSQL table 1

id name

1Tim

2Joe

3Bob

 

Have a drop down select box from table 1, and then fill in the selections in the auto-incrementing table 2, formatted as follows:

 

MYSQL table 2

id

name

 

Is this even possible?

Link to comment
Share on other sites

Rules noted.

 

Ok, to specifics.  Can you explain why this is not working?  I think there is something wrong with the following:

echo "<option value='<?php echo $donorname;?>'>$donorname</option>";

 

Out of the following code:

 

<?php $donor=@mysql_query('SELECT id, locationname FROM donors'); ?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <label>Donor:
    <select name="donor">
<?php
while ($donors=mysql_fetch_array($donor)) {
$donorname=$donors['locationname'];
echo "<option value='<?php echo $donorname;?>'>$donorname</option>";
}
?>
</select>
<input type="submit" value="SUBMIT"/>
</form>

 

There could be something wrong with this code block, but I'm really not sure:

<?php
$locationname = $_POST['donor'];
$donorid = mysql_query("SELECT id FROM donors WHERE locationname='$locationname'");

$sql = "INSERT INTO donations SET donorid='$donorid'";
mysql_query($sql);
?>

 

The select list reads the data just fine, but the

INSERT INTO donations SET donorid='$donorid'"

is not executing properly.  Lets assume that all MYSQL tables are correct and the format of the tables is irrelevant.  Any ideas?  Help is really really appreciated.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.