1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Rep Power

    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?

    PHP Code:
    $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'");

    '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
    "<script>alert('This product has been added successfully.')</script>";

    Comments on this post

    • Jacques1 disagrees : Go away, help vampire.
  2. #2
  3. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Pennsylvania, USA
    Rep Power
    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.
  4. #3
  5. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Rep Power
    Ignore that help vampire.

    All he does is cross-post his threads and then lock them soon after.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".

IMN logo majestic logo threadwatch logo seochat tools logo