Jump to content

simple counter... not so simple.


highaspen

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
Link to comment
https://forums.phpfreaks.com/topic/4576-simple-counter-not-so-simple/
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.

Archived

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

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