Forum Moderators: coopster
$arrInterestCode= array("1"=>"Arts: Art Exhibits","2"=>"Arts: Ballet",........
//1 is the code for Art Exhibits and 2 is the code for Ballet
<td align="right" class="maintextCopy"><div align="left"><em><strong>Category:</strong></em></div></td>
<td colspan="2" align="left"><select name="Category" class="selectbox" id="Category" onchange="getInterestDescList(this)";>
<?php foreach ($arrInterestCode as $key => $value) { ?>
<option value="<?=stripslashes($value)?>" <?=$objU->Category == stripslashes($value) ? "selected" : ""?>>
<?=stripslashes($value)?>
</option>
<?php } ?>
//I was trying to use Ajax to get more dynamic with this, but decided to just try to get it working static for now so I know that a couple pieces of this are unnecessary.
It is showing up in the drop down correctly, but saving to the database as the Art Exhibits or Ballet. Am I on the right track?
function insert_event($user_id=0)
{
$message= "";
$sql= "INSERT INTO tbl_events (Name, Start_date, End_date, Start_time, End_time, County, State, Website, Description, Venue_name, Category, Sub_category, User_hosted, nUser_Id)
VALUES ('".addslashes($_POST[Name])."',
'".addslashes($_POST[Start_date])."',
'".addslashes($_POST[End_date])."',
'".addslashes($_POST[Start_time])."',
'".addslashes($_POST[End_time])."',
'".addslashes($_POST[County])."',
'".addslashes($_POST[State])."',
'".addslashes($_POST[Website])."',
'".addslashes($_POST[Description])."',
'".addslashes($_POST[Venue_name])."',
'".addslashes($_POST[interestCode])."',
'".addslashes($_POST[interestDesc])."',
'".addslashes($_POST[User_hosted])."',
'{$user_id}')";
$res= @mysql_query($sql, $this->dblink);
if (!$res)
$message.= "Unable to add event, please try again later.<br>";
return $message;
}
Suppose you have
<OPTION VALUE="option value">option text</OPTION>. What this means is that "option text" will be the choice given to the user, and "option value" is what will be sent to your form. So, for instance, if you had:
and the user selected "Arts: Ballet", $_POST['Category'] would be "2".<SELECT NAME="Category">
<OPTION VALUE="1">Arts: Art Exhibits</OPTION>
<OPTION VALUE="2">Arts: Ballet</OPTION>
</SELECT>
The page I linked also includes information on grouping options together, and more fun things, so might be worth a quick read.