Jump to content

Update Problem


Chevy

Recommended Posts

For some reason none of my data in MySQL is updating.

 

Is there something wrong with this code?

 

 

  $plusone = $info['attempts']+1;

    $updatea = mysql_query("UPDATE `accounts` SET `attempts`='$plusone' WHERE `username`='$username'");

     $owed = (10*$info['attempts'])+20;
     $newpoints = $info['points']-$owed;

          if ($newpoints < "0"){
             $newpoints = 0;
          }
               $updateb = mysql_query("UPDATE `accounts` SET `points`='$newpoints' WHERE `username`='$username'");

Link to comment
https://forums.phpfreaks.com/topic/71339-update-problem/
Share on other sites

Try adding or die(mysql_error()) after running mysql_query

 

e.g.

 

  $plusone = $info['attempts']+1;

    $updatea = mysql_query("UPDATE `accounts` SET `attempts`='$plusone' WHERE `username`='$username'") or die(mysql_error());

     $owed = (10*$info['attempts'])+20;
     $newpoints = $info['points']-$owed;

          if ($newpoints < "0"){
             $newpoints = 0;
          }
               $updateb = mysql_query("UPDATE `accounts` SET `points`='$newpoints' WHERE `username`='$username'") or die(mysql_error());

 

this will produce an error message stating where your error is.

 

 

Regards

Liam

Link to comment
https://forums.phpfreaks.com/topic/71339-update-problem/#findComment-358966
Share on other sites

if you mean numeric values as int in your DB then you cant add any single ' in your set value

`attempts`='$plusone'  this will be invalid it should be

`attempts`=$plusone to tell the Db that it is actaully a numeric value so when you put ' it will be treated as string or char that wont match your fields datatypes

Link to comment
https://forums.phpfreaks.com/topic/71339-update-problem/#findComment-359706
Share on other sites

i use single quotes for EVERY database column regardless of type, at least in MySQL. single quotes around a numeric value will not affect how that value is inserted or updated, but it may prevent having malicious code inserted into your database.

 

add: i don't think the problem is data types. i think that the data you are using to update is wrong. can you write your sql to a variable and echo that variable?

Link to comment
https://forums.phpfreaks.com/topic/71339-update-problem/#findComment-359708
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.