chmpdog Posted November 23, 2008 Share Posted November 23, 2008 Hey, Recently I was creating a script where it would pull off a number from the mysql server, then subtract one from it, then update the mysql number. But I keep getting a problem when I try: it returns '-1' each time the script runs I have been trying to figure this out for about two hours now, Thanks for the help. Here is the code: $cur = mysql_fetch_array($resulm, MYSQL_ASSOC); // put the data in an array that we pull off the server $number = $cur[usernum]; $number = $number - 1; $q = "UPDATE "row" SET thenumber = '$number' WHERE id = '1'"; mysql_query($q, $database->connection); Link to comment https://forums.phpfreaks.com/topic/133852-solved-php-subtraction-problem/ Share on other sites More sharing options...
genericnumber1 Posted November 23, 2008 Share Posted November 23, 2008 try <?php $number = (int)$cur['usernum']; $number = $number - 1; ?> Link to comment https://forums.phpfreaks.com/topic/133852-solved-php-subtraction-problem/#findComment-696670 Share on other sites More sharing options...
chmpdog Posted November 23, 2008 Author Share Posted November 23, 2008 Nope. It still goes to -1. Link to comment https://forums.phpfreaks.com/topic/133852-solved-php-subtraction-problem/#findComment-696684 Share on other sites More sharing options...
genericnumber1 Posted November 23, 2008 Share Posted November 23, 2008 then try enabling E_ALL error reporting, it's likely that $cur['usernum'] isn't set. echo the variable to make sure it's set before subtracting one... Link to comment https://forums.phpfreaks.com/topic/133852-solved-php-subtraction-problem/#findComment-696691 Share on other sites More sharing options...
chmpdog Posted November 23, 2008 Author Share Posted November 23, 2008 You were right. Thanks. All I had to do was include global $cur; Link to comment https://forums.phpfreaks.com/topic/133852-solved-php-subtraction-problem/#findComment-696773 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.