Following is select option to retrieve the data from mysql db in php. On selecting the dropdown, I need to insert option value to mysql db.
<select device_id='device_id'>;
<?php
require_once('sqlcon.php');
$drop=mysql_query("select * from device");
while($row = mysql_fetch_array($drop)){
echo "<option value='" .$row['device_id']. "'>" . $row['device_id']. "</option>";
}
?>
</select>
I am using the following in add.php . Error is showing only in this line.
$device_id=$_POST['device_id'];
Also check that the device_id is set or not.
isset()
function in PHP determines whether a variable is set and is not NULL. It returns a Boolean value, that is, if the variable is set it will return true and if the variable value is null it will return false.
if(isset($_POST['device_id'])){ $device_id = $_POST['device_id']; }
your error says it all,your select box does not have a "name" attribute, you need to give it one..
<select name='device_id'>
undefined index: device_id in C:\...\ in add.php on line 55
It tells what is wrong, $_POST['device_id'] (Index = device_id) is not setted. Make sure you have <select name='device_id'>...</select>
name='device_id' = $_POST['device_id']
Use attribute onchange="document.forms[0].submit()"
to submit the form on selected option.
Add hidden field in form.
<input type="hidden" name="action" value="submit" />
Get device_id
if(isset($_POST["action"])) {
echo $_POST['device_id'];
}