Jump to content

Query not working


herghost

Recommended Posts

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.

 

 

 

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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?

 

Link to comment
Share on other sites

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();


				}

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.