...

View Full Version : Whats wrong in this code..Please help fast



Prashank
03-17-2012, 02:30 PM
Hello, all

I have a error in my php script. But the problem is i can't find it.

code is

header("Cache-Control: no-cache");
header("Pragma: nocache");

require('_config.php');

//getting the values
$iRateCount = preg_replace("/[^0-9]/","",$_REQUEST['j']);
$iRateId = preg_replace("/[^0-9a-zA-Z]/","",$_REQUEST['q']);
$iRaterId = preg_replace("/[^0-9\.]/","",$_REQUEST['t']);
$iRatedId = preg_replace("/[^0-9]/","",$_REQUEST['c']);
$ip = $_SERVER['REMOTE_ADDR'];


$vote_sent = preg_replace("/[^0-9]/","",$_REQUEST['j']);
$id_sent = preg_replace("/[^0-9a-zA-Z]/","",$_REQUEST['q']);
$ip_num = preg_replace("/[^0-9\.]/","",$_REQUEST['t']);
$units = preg_replace("/[^0-9]/","",$_REQUEST['c']);

$iUnits = '5';
if ($iRateCount > $iUnits) die("Sorry, vote appears to be invalid.");

switch ($iRateId) {
case 'ease':
easeQuery($iRateCount, $iRateId, $iRaterId, $iRatedId, $iUnits);
break;
case 'help':
helpQuery();
break;
case 'clarity':
clarityQuery();
break;
case 'interest':
interestQuery();
break;
case 'textbook':
textbookQuery();
break;
}

function easeQuery($ratecount, $rateid, $raterid, $ratedid, $units) {
$query = mysql_query("SELECT `ease_value`, `ease_count`, `ease_ids`, `user_id` FROM `pras_pr_ratings` WHERE `user_id` ='$ratedid' ");
$aquery = mysql_fetch_assoc($query);
$checkid = unserialize($aquery['ease_ids']);
$count = $aquery['ease_count'];
$currentrate = $aquery['ease_value'];
$total = $ratecount+$currentrate;
$tense = ($count == 1) ? 'vote' :' votes';

($total==0 ? $added=0 : $added= $count + 1);

((is_array($checkid)) ? array_push($checkid, $raterid) : $checkid = array($raterid));
$finalid = serialize($checkid);

$isquery = mysql_query("SELECT `ease_ids` FROM `pras_pr_ratings` WHERE `ease_ids` LIKE '%".$raterid."%' AND `user_id` = $ratedid ");
$israted = mysql_num_rows($isquery);

if ($ratecount >= '1' && $ratecount <= $units) {
$update = "UPDATE `pras_pr_ratings` SET ease_value='".$total."', ease_count='".$added."', used_ids='".$finalid."' WHERE user_id='$ratedid'";
$result = mysql_query($update);
}

}

Here the problem is in that update statement because when i echo the variables $total, $added, $finalid, $ratedid. They all give what they should but its not updating the database and database can be connected without any problems because i can read the values of $count, $currentrate etc etc..
which come from database so it obvious that it can be connected.
Am i doing something wrong please point it out.

Thanks

webdev1958
03-17-2012, 02:35 PM
Whats wrong in this code..Please help fast

When do you need a solution by?

For starters, post the output from echoing the update sql statement.

Prashank
03-17-2012, 02:42 PM
i didn't understand you properly. Do you mean echoing the update statement??
but hows that possible.

I just want to know what is wrong in the code. I think it should be something silly but i can find it.

Prashank
03-17-2012, 02:52 PM
As i mentioned before something silly.. lol

The problem was a typo in a column name. But thanks webdev and anyone who viewed this.

webdev1958
03-17-2012, 02:54 PM
i didn't understand you properly. Do you mean echoing the update statement??
but hows that possible.





$query = 'update myTable blah blah blah........';

echo $query; die();

webdev1958
03-17-2012, 02:55 PM
glad you sorted it out :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum