Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

intermittent error updating database 1

Status
Not open for further replies.

max2474

Programmer
May 10, 2012
40
GB
Hi.

I have this scripts to update my database totals:

PHP:
	while ($mppaycount <= 8)
	{
		$mpref=$_SESSION[refs][$mppaycount];
		$mprefpay=$_SESSION[refpay][$mppaycount];

		$mppayrefs=mysql_query("UPDATE members SET tottokens = tottokens+$mprefpay, tokens = tokens+$mprefpay, newtokens = newtokens+$mprefpay
			WHERE userid = '$mpref' LIMIT 1");
		$mppayrefs=mysql_query("UPDATE members SET tottokens = tottokens+$mprefpay, tokens = tokens+$mprefpay, newtokens = newtokens+$mprefpay
			WHERE userid = '1001' LIMIT 1");
		
		paylvlbonus($mpref,$mprefpay);
		$mppaycount++;
	}
	$mpmylo=$_SESSION[myleftovers];
	$mpmpb=$_SESSION[misspaymentbonus];
	$mpboth=$mpmylo+$mpmpb;	
[COLOR=red]	$mppayme=mysql_query("UPDATE members SET tottokens = tottokens+$mpmylo, tokens=tokens+$mpmylo, newtokens = newtokens+$mpmylo, bonus = bonus+$mpplancost[/color]
[COLOR=red]		WHERE userid = '1002' LIMIT 1")or die(mysql_error());[/color]
	$mppayme=mysql_query("UPDATE members SET tottokens = tottokens+$mpmpb, tokens=tokens+$mpmpb, newtokens = newtokens+$mpmpb
		WHERE userid = '1003' LIMIT 1");
	$mppayme=mysql_query("UPDATE members SET tottokens = tottokens+$mpboth, tokens=tokens+$mpboth, newtokens = newtokens+$mpboth
		WHERE userid = '1001' LIMIT 1");

everything seemed to be working fine until I deleted the test database and started again. I have noticed that upon the first run ONLY, that the highlighted line wasnt adding the bonus. (bonus = bonus+$mpplancost) yet all else is working fine.

Upon a repeated call, the value $mpplancost does get added.

Adding the "or die(mysql_error()" gives the following error:

screen said:
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 ' tokens=tokens+, newtokens = newtokens+, bonus = bonus+5500 WHERE userid = '1' at line 1

Should I be using ' or ` perhaps? Also, is the "userid = '1' " just how the error reports?

Any pointers would be great!
 
It seems to be the fact that your $mpmylo variable is empty, so you get invalid operations.

Code:
tokens=tokens+[COLOR=white red] [/color], newtokens = newtokens+[COLOR=white red] [/color], bonus = bonus+5500 WHERE userid = '1' at line 1

Which cause the query to fail. The id of 1 is probably due to the error cutting off the query line at that point.


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
ahh...lol.

added this :

PHP:
[COLOR=red]	$mpmylo="0";[/color]
[COLOR=red]	$mpmpb="0";[/color]
	$mpmylo=[COLOR=red]$mpmylo+[/color]$_SESSION[myleftovers];
	$mpmpb=[COLOR=red]$mpmylo+[/color]$_SESSION[misspaymentbonus];
and it seemed to solve it.

Silly things. Was looking a syntax error.

Many thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top