Jump to content


simple counter... not so simple.

  • Please log in to reply
2 replies to this topic

#1 highaspen

  • Members
  • PipPip
  • Member
  • 23 posts

Posted 10 March 2006 - 12:39 AM

Scratching my head on this one... just trying to add .5 to a value in a mySQL table. Here's where I am on this. I'm not getting a failure, just doesn't write.


include ('../global_vars.php');

$owner = $_COOKIE['leadowner']; #assigns value from cookie

#connect to MySQL
$conn=@mysql_connect("$dbserver", "$dbuser","$dbpass")
or die("Could not connect");

#select the specified database
$rs = @mysql_select_db("mychocolatedrink", $conn)
or die("Could not select database");

#create the query
$sql="UPDATE members SET credits=(credits + .5) WHERE user_name='$owner'";

#execute the query
or die("Could not execute query");

The column I'm trying to add .5 to is "credits" for a specific record identified in the "user_name" column.

Thanks in advance

#2 wickning1

  • Members
  • PipPipPip
  • Advanced Member
  • 405 posts

Posted 10 March 2006 - 12:44 AM

It's possible the cookie is not taking. They're notoriously unreliable. The other possibility that comes to mind is that the credits column could be set to an integer type, which would prevent adding 0.5. Maybe double check that.

#3 k.soule

  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts
  • LocationIllinois

Posted 10 March 2006 - 01:59 AM

I agree with wickning1, the cookie is definitely the first thing you want to verify...when I am debugging a script that involves a database query, I like to echo the query and kill the script directly after that. So, just to make sure everything is going according to plan, try inserting:

$sql="UPDATE members SET credits=(credits + .5) WHERE user_name='$owner'";
print $sql;

and see if everything looks correct. If you try to increment a non-interger field in a MySQL table, it will simply over-write the data in the field and insert 0.5 -- it shouldn't fail. Other than that, there really isn't anything that could fail without warning unless either members, credits, user_name or $owner don't exist.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users