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…
One request to you again,
If i add country_name in countries_wise_products table, so how i will update countries_wise_products table with both coutnry_id and country_name fields.
Thank you!!!
ismael ahm@d
Junior Poster in Training
61 posts since Mar 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
if (isset($_POST['Submit'])) {
$pro_name = $_POST['product_name'];
$pro_reg_date = $_POST['regstr_date'];
$renewal_date = $_POST['renewal_date'];
$product_shelf = $_POST['pro_shelf_life'];
$countries = $_POST['country'];
$Id=(@mysql_result(@mysql_query("SELECT max(product_id) from products"),0,0)+1);
$c_Id=(@mysql_result(@mysql_query("SELECT max(country_id) from country"),0,0)+1);
/********************************************************************************************/
if(isset($_POST['country'])) {
//$cListS = array();
$cLists = $_POST['country'];
$product_id = $Id;
foreach($cLists as $countryid) {
$query = "INSERT INTO country_wise_products (country_id, product_id, product_name) VALUES ('$countryid', '$product_id', '$pro_name')";
//mysql_query($query) or die ("country_wise_product not updated!!! ");
if (!$res = mysql_query($query)){
echo mysql_error(); die();
}
}
}
/******************************************************************************************/
$sql1 = "INSERT INTO products (product_id, product_name, pro_regt_date, pro_renew_date, product_shelf_life) VALUES
('$Id', '$pro_name', '$pro_reg_date', '$renewal_date', '$product_shelf')";
$sql1_result = mysql_query($sql1) or die (mysql_error());
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<form name="pro_reg_form" id="form1" method="post" action="">
<table width="40%" border="1" align="center" cellpadding="0" cellspacing="0">
<tr align="center">
<td colspan="2">Product Regisration Tracker</td>
</tr>
<tr>
<td>Product Name </td>
<td><input name="product_name" type="text" id="product_name" /></td>
</tr>
<tr>
<td>Product Regsiterd Date </td>
<td><input name="regstr_date" type="text" id="regstr_date" /></td>
</tr>
<tr>
<td>Product Renewal Date </td>
<td><input name="renewal_date" type="text" id="renewal_date" /></td>
</tr>
<tr>
<td>Product Shelf Life </td>
<td><input name="pro_shelf_life" type="text" id="pro_shelf_life" /></td>
</tr>
<tr>
<td valign="top">Country</td>
<?php $stqry = "select * from country order by country_name";
$cat_rs = mysql_query($stqry); ?>
<td><select name="country[]" multiple="multiple" id="country">
<?php
// while($obcat=@mysql_fetch_object($rscat))
while ($cat_row = @mysql_fetch_object($cat_rs)) {
echo "<option value='$cat_row->country_id'>$cat_row->country_name</option>";
}?>
<!-- <option>UAE</option>
<option>KSA</option>
<option>Kwait</option>
<option>Pakistan</option>
<option>India</option> -->
<?php //} ?>
</select>
</td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="Register" /></td>
</tr>
</table>
</form>
</body>
</html>
ismael ahm@d
Junior Poster in Training
61 posts since Mar 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
ismael ahm@d
Junior Poster in Training
61 posts since Mar 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 8 Months Ago by
broj1,
adam.adamski.96155,
Bachov Varghese
and 1 other