How to insert selected values from a table to a dropdown list to another table with php and mySql ?
used following code to select from drop down list by using php...
$mysqlserver="localhost";
$mysqlusername="myname";
$mysqlpassword="mypass";
$link=mysql_connect(localhost, $mysqlusername, $mysqlpassword) or die ("Error connecting to mysql server: ".mysql_error());
$dbname = 'mydb';
mysql_select_db($dbname, $link) or die ("Error selecting specified database on mysql server: ".mysql_error());
$cdquery="SELECT dash_id,dash_name FROM dashitem";
$cdresult=mysql_query($cdquery) or die ("Query to get data from firsttable failed: ".mysql_error());
while ($cdrow=mysql_fetch_array($cdresult)) {
$did=$cdrow["dash_id"];
$dname=$cdrow["dash_name"];
echo "<option vlaue=\"$did\">
$did ::$dname
</option>";
}
?>
</select>
Here's my suggestion :
In your form do this :
<select name="dropdown">
Drop down list
</select>
Then in your PHP do this :
$drop = $_POST['dropdown'];
So the value now is passed to $drop. Then you can just transfer to SQL and it will be easier passing value via dropdown using this way.
You have a typo: "value" instead of "vlaue" :)
echo '<option value="' . $did . '">' . $did . ' ::' . $dname . '</option>';
It's a good practice to use single quotes to print the code. This way, you'll be able to use double quotes in the HTML code.
Also, use mysqli or PDO instead of the deprecated "mysql_*" functions.