PDA

View Full Version : inserting data


john1r411685
07-24-2010, 03:01 PM
Hi

I am trying to pick-up the response when a user ticks a checkbox called – version_id_ac. And or

A user has the option to select either one or both checkboxes in a form and I am trying to store which options they selected in to a mysql table called user_version with a column in the table called version_id

Please see the code below I don’t get anything inserted, please would someone tell me where I am going wrong with my syntax

if ('$data[version_id_ac] == true'); {
$sql_insert = "INSERT into `user_version`
(`version_id`,`id`)
VALUES
('$data[version_id]','$user_id')
"; }

mysql_query($sql_insert,$link) or die("Insertion Failed:" . mysql_error());
$user_id = mysql_insert_id($link);



if ('$data[version_id_dc] = true') {
$sql_insert = "INSERT into `user_version`
(`version_id`,`id`)
VALUES
('$data[version_id_DC]','$user_id')
"; }

Jason Byrnes
07-26-2010, 07:47 AM
$data[version_id_dc] is not the correct way to refer to a posted form element value.


If the forms method is set to post, the proper code to get the value would be:

$_POST['elementName']


For a checkbox, the value that is posted will be the value added to the value attribute:
<input name="checkbox" type="checkbox" id="checkbox" value="my value" />

to check if this checkbox was checked, the code would be:

if(isset($POST['checkbox']) && $POST['checkbox'] != "") {