herghost Posted November 19, 2010 Share Posted November 19, 2010 Evening everybody, hoping someone can see my error here! $sql="INSERT INTO transactions (t_ref, m_affid, m_name, order_val, order_date, order_status, u_id, u_comm) VALUES('$t_ref', '$m_affid', '$m_name', '$order_val', '$order_date', '$order_status', '$u_id', '$u_comm')"; if (!mysql_query($sql)) { mysql_error(); } else { $newq = mysql_query("SELECT * FROM userbalance WHERE u_id = '$u_id'"); echo mysql_error(); $row = mysql_fetch_assoc($newq); $cpending = $row['pending']; $npending = $cpending + $u_comm; $updatepending = "INSERT into userbalance (pending) VALUES ('$npending') WHERE u_id = '$u_id'"; if (!mysql_query($updatepending)) { mysql_error(); } } Basically the 1st query works and inserts the data correctly, however once it gets to $newq = mysql_query("SELECT * FROM userbalance WHERE u_id = '$u_id'"); this query does not insert anything, no errors. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 19, 2010 Share Posted November 19, 2010 And have you echoed the query to be sure it contains the values you'd expect it to contain? Quote Link to comment Share on other sites More sharing options...
herghost Posted November 19, 2010 Author Share Posted November 19, 2010 Hi Pickachu, Thanks for you speedy reply as always, { $newq = mysql_query("SELECT * FROM userbalance WHERE u_id = '$u_id'"); echo mysql_error(); $row = mysql_fetch_assoc($newq); $cpending = $row['pending']; echo "<br>" . $cpending . "<br />"; $npending = $cpending + $u_comm; echo "<br>" . $npending . "<br />"; echo $u_id; $updatepending = "INSERT into userbalance (pending) VALUES ('$npending') WHERE u_id = '$u_id'"; if (!mysql_query($updatepending)) { mysql_error(); } } Yes cpending, npending and u_id all echo correctly, just the query is not working. Ive double checked the table is definitely called userbalance, and the two fields involved are definitely called pending and u_id! Quote Link to comment Share on other sites More sharing options...
herghost Posted November 19, 2010 Author Share Posted November 19, 2010 ah, if I add an echo to the mysql_error I get: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE u_id = '23'' at line 1 Can I not use a where statement like this in an insert into query? Quote Link to comment Share on other sites More sharing options...
herghost Posted November 19, 2010 Author Share Posted November 19, 2010 Turns out no, no I cant! Changed it to an update but still not inserting values: { $newq = mysql_query("SELECT * FROM userbalance WHERE u_id = '$u_id'"); echo mysql_error(); $row = mysql_fetch_assoc($newq); $cpending = $row['pending']; echo "<br>" . $cpending . "<br />"; $npending = $cpending + $u_comm; echo "<br>" . $npending . "<br />"; echo $u_id; $updatepending = "UPDATE userbalance SET pending= '$npending' WHERE u_id = '$u_id'"; echo mysql_error(); } Quote Link to comment Share on other sites More sharing options...
herghost Posted November 19, 2010 Author Share Posted November 19, 2010 D'oh got it mysql_query ("UPDATE userbalance SET pending= '$npending' WHERE u_id = '$u_id'"); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.