June 27th, 2013, 02:06 AM
How to populate one table with values from another table
i have a table with the following columns
pord_name, prod_brand, prod_photo, prod_desc
and another table with the following columns
prod_name, prod_brand, prod_photo, prod_desc, cat, subcat, prod_price, prod_w_c
i have a for add_prod.php to add products
the prod name is displayed in a select which when product name is selected, populates the prod brand select. on selecting an option in the prod brand, the prod desc is displayed
when i click on the add button, prod_name, prod_brand, etc are added except the prod_desc and prod_photo
can i know what is wrong with the code here please?
$username = $_SESSION['username'];
$sql=mysql_query("select user_id from tbllogin where username = '$username'");
$sql=mysql_query("INSERT INTO tbl_product(user_id, prod_name, prod_brand, prod_desc, prod_price, cat, subcat, prod_w_c) VALUES('$row[user_id]', '$prod_name', '$prod_brand', '$prod_desc', '$prod_price', '$cat', '$subcat', '$prod_w_c') SELECT FROM tbl_prodstd (prod_photo, prod_desc) WHERE prod_name='$prod_name'");
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
echo "<script>alert('This product has been added successfully.')</script>";
Comments on this post
June 27th, 2013, 06:40 AM
You use $prod_desc in your query but it's not present in the rest of your code.
HEY! YOU! Read the New User Guide and Forum Rules
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin
"The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002
Think we're being rude? Maybe you asked a bad question
or you're a Help Vampire.
Trying to argue intelligently? Please read this.
June 27th, 2013, 07:33 AM