Jump to content

Archived

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

highaspen

simple counter... not so simple.

Recommended Posts

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.

--------------
<?php

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
$rs=mysql_query($sql,$conn)
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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;
die;

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.

Share this post


Link to post
Share on other sites

×

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.