highaspen Posted March 10, 2006 Share Posted March 10, 2006 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.--------------<?phpinclude ('../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 Quote Link to comment https://forums.phpfreaks.com/topic/4576-simple-counter-not-so-simple/ Share on other sites More sharing options...
wickning1 Posted March 10, 2006 Share Posted March 10, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/4576-simple-counter-not-so-simple/#findComment-15985 Share on other sites More sharing options...
k.soule Posted March 10, 2006 Share Posted March 10, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/4576-simple-counter-not-so-simple/#findComment-16004 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.