...

View Full Version : Please Check My code .Cant find the error



ajloun
02-09-2010, 10:57 PM
Hello

I have this Code , to enable , Disable Comment . . The Disable is working But the Disable Dose not , i get the OK Message but when i check the Table it did not get uodated with the New value ..

This suppose to update the Com filed with 0,1 ... and update the time also ..

when call the file for disable , it works and the filed get updated with new valuse , But the disable dose not work .. and no errors comes back so i cant figuer out why not .. However it works ok in the localhost , it just when i put it on my live site ..


<?php
$date = time();
$id = HtmlSpecialchars($_GET['id']);

if (HtmlSpecialchars($_GET['action']) == "disable"){


$query =mysql_query("UPDATE ".$DB->prefix("test")." SET com='0' , date='$date' WHERE id='$xid' ")
or die("Could Not update the Mysql Table");
if (!$query){

echo "error";
}else{

echo "disabled";
}
}
if (HtmlSpecialchars($_GET['action']) == "enable"){

$data =mysql_query("UPDATE ".$DB->prefix("test")." SET com='1' , date='$date' WHERE id='$xid' ")
or die("Could Not update the Mysql Table");

if (!$data){
echo "error";

}else{
echo "enable";
}
}
?>

Fou-Lu
02-09-2010, 11:37 PM
Sorry which isn't working?
BTW, these blocks are pointless:


if (!$query){

echo "error";
}else{

echo "disabled";
}

$query and $data later will never be false; if they were the die would have kicked in.

Aside from $xid not existing, it looks fine. Chances are it doesn't work because these variables are incorrect and you cannot update a field with an id value of nothing (unless such a record exists of course).

MattF
02-09-2010, 11:50 PM
You ought to be running intval on the $id too, rather than what appears to be some variant of htmlspecialchars.



$id = intval($_GET['id']);

ajloun
02-09-2010, 11:54 PM
thx Guys ..i replaced it with intval and fixed the xid .., still won't update the com filed .. however it dose update the date..

MattF
02-10-2010, 12:05 AM
If it's updating the date field, then there's no reason why the com field should remain untouched unless the queries are running in the opposite order to how you're expecting, i.e: the disable block is being called instead of enable and vice versa.

Add an echo/print after the if clauses to check whether disable/enable are called respectively when requested.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum