0

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));
3
Contributors
4
Replies
6
Views
7 Years
Discussion Span
Last Post by luap599
0

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.

Edited by urtrivedi: n/a

0

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

0
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

Edited by luap599: to show more detail

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.