I have a page on my site where the user can add a new record to a table in a database by using a fairly standard form. To ensure data consisitency I want the user to be able to select standard responses in certain fileds. For example one field is called "eventtype". This filed determines whether an event which our charity is working at is a fundraiser, profile raiser or other type of event (e.g. recruitment). The code for my form looks like this:
I want the user to be able to select from a combo box an option value say of "fundraiser", "Profile", "Recruitment" or some other hard coded answer. I want the selection then to populate the fieldd in my database with the selected answer once the Submit button is clicked. The connection and field information is shown below:
Can anyone help me please?
Code:
<form id="form1" name="form1" method="post" action="">
<table width="49%" border="0" align="center">
<tr>
<td>eventname</td>
<td><input name="eventname" type="text" id="eventname" size="64"/></td>
</tr>
<tr>
<td>Location</td>
<td><input name="eventlocation" type="text" id="eventlocation" size="64" /></td>
</tr>
<tr>
<td>Status</td>
<td><input name="eventstatus" type="text" id="eventstatus" /></td>
</tr>
<tr>
<td>Type of Event</td>
<td><input name="eventtype" type="text" id="eventtype" /></td>
</tr>
<tr>
<td>Date</td>
<td><input name="eventdate" type="Date" id="eventdate" /></td>
</tr>
<tr>
<td>Start Time</td>
<td><input name="starttime" type="text" id="starttime" /></td>
</tr>
<tr>
<td>End Time</td>
<td><input name="endtime" type="text" id="endtime" /></td>
</tr>
<tr>
<td>Coordinator</td>
<td><input name="coordinator" type="text" id="coordinator" /></td>
</tr>
<tr>
<td>Comments</td>
<td><textarea name="comments" cols="64" id="comments"></textarea></td>
</tr>
<tr>
<td>Funds Raised</td>
<td><input name="fundsraised" type="decimal(5,2)" id="fundsraised" /></td>
</tr>
<tr>
<td>Financial Year</td>
<td><input name="financialyear" type="text" id="financialyear" /></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="Submit" /></td>
</tr>
</table>
</form></p></td> </tr></table></td> </tr></table>
I want the user to be able to select from a combo box an option value say of "fundraiser", "Profile", "Recruitment" or some other hard coded answer. I want the selection then to populate the fieldd in my database with the selected answer once the Submit button is clicked. The connection and field information is shown below:
Code:
/connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
//select a database to work with
$selected = mysql_select_db("eachfrie_Events",$dbhandle)
or die("Could not select eachfrie_Events");
// query db and loop through rows example
$field3 = $_POST['eventname'];
$field4 = $_POST['eventlocation'];
$field5 = $_POST['eventtype'];
$field6 = $_POST['eventstatus'];
$field7 = $_POST['eventdate'];
$field8 = $_POST['starttime'];
$field9 = $_POST['endtime'];
$field10 = $_POST['coordinator'];
$field11 = $_POST['comments'];
$field12 = $_POST['fundsraised'];
$field13 = $_POST['financialyear'];
if($field3){
$sql = "
INSERT INTO
`tblEvents` (
`eventname`
,`eventlocation`
,`eventtype`
,`eventstatus`
,`eventdate`
,`starttime`
,`endtime`
,`coordinator`
,`comments`
,`fundsraised`
,`financialyear`
) VALUES (
'".$field3."'
,'".$field4."'
,'".$field5."'
,'".$field6."'
,'".$field7."'
,'".$field8."'
,'".$field9."'
,'".$field10."'
,'".$field11."'
,'".$field12."'
,'".$field13."'
)
;
";
echo $sql; //debug line
mysql_query($sql);
Can anyone help me please?