can someone point me out whats wrong with my codes? im having trouble finding out whats the problem with my code because it doesnt display error and i cannot see the result in the data include "/class/include.php"; $tempID = mysql_real_escape_string ($_POST['p_id']); $tempQTY = mysql_real_escape_string ($_POST['p_qty']); $tempPRICE =mysql_real_escape_string ($_POST['p_price']); $tempTOTAL = mysql_real_escape_string ($_POST['p_total']); $tempPAID = mysql_real_escape_string ($_POST['amount_paid']); //insert in yo p sales $query = "INSERT INTO p_sales (sales_id, product_id, amount_paid, sales_date, sales_qty, price, total_price) VALUES ('', '$tempID', '$tempPAID', now(), '$tempQTY','$tempPRICE', '$tempTOTAL')"; mysql_query($query); // transaction id $id_gen=mysql_insert_id(); //balance $sql=mysql_fetch_row(mysql_query("SELECT product_qty FROM productinfo WHERE product_id = '$tempID'")); //ledger insertion $sql2 = "INSERT INTO p_ledger (product_id, trans_type, trans_id, invent_dec, balance_qty) VALUES ('$tempID', 'SALE', '$id_gen','$tempQTY', '".$sql[0]."')"; mysql_query($sql2); //balance update $update="UPDATE productinfo SET balance_qty =(balance_qty - '$tempQTY') WHERE product_id = '$tempID'"; mysql_query($update); mysql_close(); Code (markup):
try this code <?php include '/class/include.php'; // insert in yo p sales $query1 = mysql_query("INSERT INTO p_sales (sales_id, product_id, amount_paid, sales_date, sales_qty, price, total_price) VALUES ('', '".mysql_real_escape_string($_POST['p_id'])."', '".mysql_real_escape_string($_POST['amount_paid'])."', '".now()."', '".mysql_real_escape_string($_POST['p_qty'])."', '".mysql_real_escape_string($_POST['p_price'])."', '".mysql_real_escape_string($_POST['p_total'])."')"); // transaction id $id_gen = mysql_insert_id(); // balance $query2 = mysql_fetch_row(mysql_query("SELECT product_qty FROM productinfo WHERE product_id = '".mysql_real_escape_string($_POST['p_id'])."'")); // ledger insertion $query3 = mysql_query("INSERT INTO p_ledger (product_id, trans_type, trans_id, invent_dec, balance_qty) VALUES ('".mysql_real_escape_string($_POST['p_id'])."', 'SALE', '$id_gen','".mysql_real_escape_string($_POST['p_qty'])."', '".$query2[0]."')"); // balance update $query4 = mysql_query("UPDATE productinfo SET balance_qty = balance_qty - '".mysql_real_escape_string($_POST['p_qty'])."' WHERE product_id = '".mysql_real_escape_string($_POST['p_id'])."'"); mysql_close(); ?> PHP: if it doesn't work maybe it's your database structure what's wrong ? so it's probably not adding the data..
for each variable add single qoutes like this : $tempPAID = "'" . mysql_real_escape_string ($_POST['amount_paid']) . "'"; Code (markup): And in the query remove the single quotes around the variable : '$tempPAID' ===> $tempPAID Code (markup):
If sales_id is set to auto increment in your database, then you will not be able to insert a NULL value (as you have done so in your query). And if that does not work, put "or die(mysql_error());" (w/o quotes) after each query you execute to find out if they are returning with errors.
delete your table than re create it. Remember that the $query and other variables are strings, where you have put now() should not work that's incorrect syntax, try $now = now();. Also when adding the variables to the query strings, use the " . " method because it is the right syntax, stick to correct syntax and your code will run faster and better than if you don't.