Update database with value from listbox (function)
Posted: Tue Mar 09, 2004 1:42 am
I have the following function to create a listbox which is used several times in my scripts for differnt listboxes:
My first instance of the listbox is for the user to select a title:
My question is how do I now update the value chosen by the user into the database?
I've tried:
But that just updates the database with "Array".
Any ideas?
Thanks in advance
Code: Select all
function enhanced_list_box($options){
$sql = "select " . $options['id_field'];
$sql .= ", " . $options['value_field'];
$sql .= " from " . $options['table'];
$result = mysql_query($sql)
or die("error in SQL");
echo '<select name="'. $options['id_field']. '" size="1">';
while ($row = mysql_fetch_array($result, MYSQL_NUM))
{
if($row[1] == $options['highlight_id']) {
echo '<option value="'. $row[0]. '" SELECTED>'.
$row[1]. '</option>';
} else {
echo '<option value="'. $row[0]. '">'.
$row[1]. '</option>';
}
}
echo '</select>';
}Code: Select all
<? enhanced_list_box(array(
'table' => 'ctitle',
'id_field' => 'id',
'value_field' => 'title',
'highlight_id' => $Title));
?>I've tried:
Code: Select all
"UPDATE customers SET "
." Title="".$_POST.$options['title'].""";Any ideas?
Thanks in advance