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