Jump to content

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.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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