Hi all, I have a bit of PHP code that is really taking a toll on me. To simplify, I have a table where three of the columns are forign keys (event_type, accommodation_type and public_user). I am dynamically creating a set of radio buttons and I have set the ID attribute on each imput value correctly.
$result2 = mysql_query("SELECT * FROM event_type", $connection);
if(!$result2){
die("Database query failed: " . mysql_error());
}
$event = mysql_fetch_array($result2);
echo "<input type='radio' name='event_type' value='";
echo $event["id"];
echo "' > ";
echo $event['name'];
echo "</input><br /><br />";$result4 = mysql_query("SELECT * FROM accommodation_type", $connection);
if(!$result4){
die("Database query failed: " . mysql_error());
}
while($row = mysql_fetch_array($result4)){
if($row["id"] == 7 || $row["id"] == 8){
echo"<tr><td>";
echo $row["name"] ;
echo"</td><td>$";
echo $row["price"];
echo ".00</td><td>";
echo "<input type='radio' name='accommodation_type' value='";
echo $row["id"];
echo "' />";
echo "</td></tr>";
}
}
I retrieved the correct id from the query. Thus after submitting the form with POST, I go on to do some minor validation and preped the names from my post as folows.
$event_type = trim(mysql_prep($_POST['event_type']));
$accommodation_type= trim(mysql_prep($_POST['accommodation_type']));
$public_user = trim(mysql_prep($_POST['public_user']));
$comments = trim(mysql_prep($_POST['comments']));
$grand_total = trim(mysql_prep($_POST['grand_total']));
I then proceded to write insert statements to insert the dada into the relevant tables. This requires two queries as follows.
$query = "INSERT INTO event_registration (event_type, accommodation_type, public_user, comments, grand_total) VALUES ('{$event_type}','{$accommodation_type}','{$public_user}','{$comments}','{$grand_total}')";
$query1 = "INSERT INTO additional_member (first_name, last_name, gender, age_group, public_user) VALUES ('{$first_name}','{$last_name}','{$gender}','{$age_group}','{$public_user}')";
$result = mysql_query($query, $connection);
$result1 = mysql_query($query1, $connection);
The query1 works as expected, hower the first querry fails to insert the data. It says undefined index at the lines where I have
$event_type = trim(mysql_prep($_POST['event_type']));
$accommodation_type= trim(mysql_prep($_POST['accommodation_type']));
I am not entirely sure where things went wrong. Everything seems to be set up correctly and the data from the form just refuses to be saved.
Any ideas ?