i have three db tables
products
product_id- Name
1 | hairoil
2 | lotion
3 | cream
Countries
country_id- Name
1 | UAE
2 | France
3 | UK
Now i wanna that when select multiple countries for one product from Html form, then in third db table should insert data like this<br />
<p>countries_product
c_id | coutry_id | product_id
1 | 1 | 2
2 | 3 | 2
3 | 1 | 3
4 | 2 | 3
5 | 3 | 3
Please let me know from your valuable suggestions<br />
Thanks
ismael ahm@d
0
Newbie Poster
Recommended Answers
Jump to Post// if values exist in $_POST (or $_GET if you use it) if(isset($_POST['product_id']) && isset($_POST['country_id'])) { // product ID $product_id = $_POST['product_id']; // begin the query $query = 'INSERT INTO countries_product (coutry_id, product_id) VALUES '; // add coutry ID's foreach($_POST['country_id'] as $country_id) { $query = "($country_id, $product_id),"; …
Jump to PostThis is wrong:
<option value= '1' <?php echo $cat_row->country_id; ?> >
It should be:
<option value= "<?php echo $cat_row->country_id; ?>" >
Jump to PostA problem could lie in the select element in the code below:
while ($cat_row = @mysql_fetch_object($cat_rs)) {?> <option value= '1' <?php echo $cat_row->country_id; ?> > <?php echo $cat_row->country_name; ?> </option> <!-- <option>UAE</option> <option>KSA</option>
where statement
<option value= '1'
should be only<option value=
(omitting …
Jump to PostPut this in the beginning of your script:
<?php // if values exist in $_POST, insert them in the database if(isset($_POST['product_id']) && isset($_POST['country_id'])) { // uncomment this to inspect the $_POST array // it should contain product_id and an array of country_ids // die(print_r($_POST, 1)) // product …
Jump to PostHave a look at the error mysql reports:
if (!$res = mysql_query($query)){ echo mysql_error(); die(); }
It should give you the specific problem.
All 25 Replies
broj1
356
Humble servant
Featured Poster
ismael ahm@d
0
Newbie Poster
simplypixie
123
Posting Pro in Training
broj1
356
Humble servant
Featured Poster
ismael ahm@d
0
Newbie Poster
ismael ahm@d
0
Newbie Poster
broj1
356
Humble servant
Featured Poster
ismael ahm@d
0
Newbie Poster
broj1
356
Humble servant
Featured Poster
ismael ahm@d
0
Newbie Poster
broj1
356
Humble servant
Featured Poster
Bachu
45
Newbie Poster
adam.adamski.96155
43
Junior Poster
ismael ahm@d
0
Newbie Poster
Bachu
45
Newbie Poster
ismael ahm@d
0
Newbie Poster
adam.adamski.96155
43
Junior Poster
ismael ahm@d
0
Newbie Poster
ismael ahm@d
0
Newbie Poster
adam.adamski.96155
43
Junior Poster
ismael ahm@d
0
Newbie Poster
adam.adamski.96155
43
Junior Poster
ismael ahm@d
0
Newbie Poster
adam.adamski.96155
43
Junior Poster
ismael ahm@d
0
Newbie Poster
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.