Here is some debug output from a script that I am helping on. The sql lines below is the echo of a var $sql. One is before the mysql_query command and the other is after. Just to make sure the sql is sending the right string.
[DEBUG] where=/forumindex.php?debug=1
[DEBUG] true
[DEBUG] where=/forumindex.php?debug=1
[DEBUG] Deleteing Old Online Records
[DEBUG] Updating Online Table
[DEBUG] user
[DEBUG] loc=/forumindex.php?debug=1
[DEBUG] sql=UPDATE online SET time='1020193223', location='/forumindex.php?debug=1' WHERE userid='16'
[DEBUG] sql=UPDATE online SET time='1020193223', location='/forumindex.php?debug=1' WHERE userid='16'
[DEBUG] result=1
[DEBUG] 1
[DEBUG]
Also I turned on logging on the mysqld and checked the log to verify that the same query was being accepted by the server, and it was.
The problem is when I look at the db the information is all correct accept 90% of the time loc is '/'(just a slash).
If I cut and paste the output from this debug info to the mysql client it executes fine and the data shows up in the db.
Me and the original programmer have re-wrote the code and cheanged everything so much and we still can't find the bug.
If anyone can see it please post what you find.
function updateonlinetable2($userid,$name,$loc,$ip)
{
global $debug,$mysql;
discardoldonline2();
$altered=time()+3600;
$ok=0;
if($debug == 1){
echo "[DEBUG] Updating Online Table<BR>";
}
//$loc='/forumindex.php';
if(!isonline2($userid,$name))
{
if($debug == 1){
echo "[DEBUG] loc=$loc<BR>";
}
$sql="INSERT INTO online SET userid=$userid,
name='$name',
location='".$loc."',
ip='$ip',
time='$altered'";
}
else
{
if($userid!=0)
{
if($debug == 1){
echo "[DEBUG] user<BR>[DEBUG] loc=$loc<BR>";
}
$sql="UPDATE online SET
time='$altered',
location='".$loc."'
WHERE userid='$userid'";
}
else
{
if($debug == 1){
echo "[DEBUG] guest<BR>[DEBUG] loc=$loc<BR>";
}
$sql="UPDATE online SET
time='$altered',
location='".$loc."'
WHERE userid='$userid' AND name='$name'";
}
}
if($debug == 1){
echo "[DEBUG] sql=$sql<BR>";
}
$result=@mysql_query($sql,$mysql) or die("Bad SQL");
if($debug == 1){
echo "[DEBUG] sql=$sql<BR>";
}
if($debug == 1){
echo "[DEBUG] result=$result<BR>[DEBUG] ".mysql_affected_rows().
"<BR>[DEBUG] ".mysql_error()."<BR>";
}
return($result);
}