php - not putting id into variable -


the purpose of script productid product user has entered form, id of order has been created in previous script , put these 2 values order_line_item table.

i have identified error occurs because there no value in variable called '$db_productid' , when insert value database tries product id can link there no product id of 0 returns following error:

cannot add or update child row: foreign key constraint fails (the_shop.order_line_item, constraint order_line_item_ibfk_1 foreign key (productid) references product (productid) on delete cascade on update cascade)

this script:

  if (isset($_get['submit1'])) {     $dblastid = $_session['lastid'];     $db_product_name = $_get['product_name'];      $query = "select productid product product_name = '$db_product_name'";     $result = mysql_query($query)             or die(mysql_error());     $fetch = mysql_fetch_assoc($result);     $db_productid = $fetch['productid'];     $lastid = $_session['lastid'];      $query = "insert `the_shop`.`order_line_item`( `orderid` , `productid` ) values ( '$lastid', '$db_productid')";     $result = mysql_query($query)             or die(mysql_error()); } 

upon further debugging have discovered string user inputs form appear in '$db_product_name' , product name on database in product table

for reason teacher gave impression needed insert variables this

.$db_username. meaning username stored user intended dots before , after entry... anyway inserting records without doing , works fine... funny teacher see website works fine without doing :)


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -