Hi my first insert statment works ok, My problem is that I wish to insert all the selected options passed from the form. into my user_req_opt table. Some items only have 1 option others may have 10 options.

$sql = "insert into user_requests(rq_id, user_id, code_ref, code_id, cat_id, opt_yn, rq_qty, rq_unit, rq_type, rq_date) values(null, '$user_id', '".$_POST[code_ref]."', '".$_POST[code_id]."', '".$_POST[cat_id]."', '".$_POST[opt_yn]."', '".$_POST[rq_qty]."', 'ea', 'code', now())";
$res = mysqli_query($mysqli, $sql) or die (mysqli_error($mysqli));

$qid = mysqli_insert_id($mysqli);

if($_POST[opt_yn] != 'n'){

$opt = "insert into user_req_opt(rq_id, opt_ref, opt_value) values('".$qid."', '".$_POST[opt_ref]."', '".$_POST[opt_value]."')";
$result = mysqli_query($mysqli, $opt) or die (mysqli_error($mysqli));

You may continue inserting using following statement

if($_POST[opt_yn1] != 'n'){ $opt = "insert into user_req_opt(rq_id, opt_ref, opt_value) values('".$qid."', '".$_POST[opt_ref1]."', '".$_POST[opt_value1]."')";$result = mysqli_query($mysqli, $opt) OR die (mysqli_error($mysqli));
}

if($_POST[opt_yn2] != 'n'){ $opt = "insert into user_req_opt(rq_id, opt_ref, opt_value) values('".$qid."', '".$_POST[opt_ref2]."', '".$_POST[opt_value2]."')";$result = mysqli_query($mysqli, $opt) OR die (mysqli_error($mysqli));
}
.
.
.
.
.
.
.

I have assumed your post variables. You should change it according to your form.

could you please post your table structure so we can get a better understanding of your requirements.

Thank you for your response, and yes your code dose work if I were using hard coded form to submit the data.

However; my option forms are dynamically generated via PHP script with information pulled from the product options table.

I am using a set of radio boxes to allow viewers to select the options the wish to have!

Again Thank you for your reply

Paul

CREATE TABLE `user_req_opt` (
  `rq_id` int(11) NOT NULL,
  `opt_ref` char(2) NOT NULL,
  `opt_value` varchar(30) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1

The option users select from ane stored in the table below

CREATE TABLE `codes_opt` (
`code_id` int(11) NOT NULL,
`opt_ref` char(2) NOT NULL,
`opt_name` varchar(30) NOT NULL,
`opt_value` varchar(30) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.