We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,328 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion
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…

Hey, glad you solved your problem, kudos to broj1 also, don't forget to mark thread as solved :D

adam.adamski.96155
Junior Poster
189 posts since Oct 2012
Reputation Points: 43
Solved Threads: 40
Skill Endorsements: 4

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

Can you post your code up till now?

adam.adamski.96155
Junior Poster
189 posts since Oct 2012
Reputation Points: 43
Solved Threads: 40
Skill Endorsements: 4
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">&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</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
foreach($cLists as $countryid) {
    $innerSQL = "SELECT country_name FROM country WHERE country_id=$countryid"; //get country name for each new entry.
    $query = "INSERT INTO country_wise_products (country_id, product_id, product_name, country_name) VALUES ('$countryid', '$product_id', '$pro_name', ($innerSQL))";

It doesn't make sense to me to have the country name in that table, as you already have a look-up table for countries and ID's, but if you want to do it, I think the above code is what you need. Backup your database before you let my code near your server and this will not work until you have added a new column to your DB profiled for text entry.

adam.adamski.96155
Junior Poster
189 posts since Oct 2012
Reputation Points: 43
Solved Threads: 40
Skill Endorsements: 4

Okay

Thanks and Regards

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

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
 
© 2013 DaniWeb® LLC
Page generated in 0.3072 seconds using 2.69MB