recent php upgrade has stoped part of my rating script from working.
Hi All
my host recently upgaded to php 5.3 and since then my rating script has stopped working correctly,
it still counts the votes etc but it doesnt show the user the value they have voted once they click on the rating, which can be very confusing to the user a
i have asked over in the js forum for the guys to check out my js code to see if there is anything wrong with that and i thought i'd check out my php files associated with this script
so i opened up one of the php files in my browser and i got some errors on the screen, now im not sure if this is because the rest of the script hasnt been run first etc but here are the errors im getting
Code:
Notice: Undefined index: j in /customers/kernow-connect.com/kernow-connect.com/httpd.www/rpc.php on line 21
Notice: Undefined index: q in /customers/kernow-connect.com/kernow-connect.com/httpd.www/rpc.php on line 22
Notice: Undefined index: t in /customers/kernow-connect.com/kernow-connect.com/httpd.www/rpc.php on line 23
Notice: Undefined index: c in /customers/kernow-connect.com/kernow-connect.com/httpd.www/rpc.php on line 24
Notice: Undefined variable: rating_unitwidth in /customers/kernow-connect.com/kernow-connect.com/httpd.www/rpc.php on line 67
Notice: Undefined variable: rating_unitwidth in /customers/kernow-connect.com/kernow-connect.com/httpd.www/rpc.php on line 68
unit_long|
require('dbinfo.php'); // get the db connection info
$rating_unitwidth = "";
//getting the values
$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']);
$ip = $_SERVER['REMOTE_ADDR'];
if ($vote_sent > $units) die("Sorry, vote appears to be invalid."); // kill the script because normal users will never see this.
//connecting to the database to get some information
$query = mysql_query("SELECT total_votes, total_value, used_ips FROM temp WHERE id='$id_sent' ")or die(" Error: ".mysql_error());
$numbers = mysql_fetch_assoc($query);
$checkIP = unserialize($numbers['used_ips']);
$count = $numbers['total_votes']; //how many votes total
$current_rating = $numbers['total_value']; //total number of rating added together and stored
$sum = $vote_sent+$current_rating; // add together the current vote value and the total vote value
$tense = ($count==1) ? "vote" : "votes"; //plural form votes/vote
// checking to see if the first vote has been tallied
// or increment the current number of votes
($sum==0 ? $added=0 : $added=$count+1);
// if it is an array i.e. already has entries the push in another value
((is_array($checkIP)) ? array_push($checkIP,$ip_num) : $checkIP=array($ip_num));
$insertip=serialize($checkIP);
//IP check when voting
$voted=mysql_num_rows(mysql_query("SELECT used_ips FROM temp WHERE used_ips LIKE '%".$ip."%' AND id='".$id_sent."' "));
if(!$voted) { //if the user hasn't yet voted, then vote normally...
if (($vote_sent >= 1 && $vote_sent <= $units) && ($ip == $ip_num)) { // keep votes within range, make sure IP matches - no monkey business!
$update = "UPDATE temp SET total_votes='".$added."', total_value='".$sum."', used_ips='".$insertip."' WHERE id='$id_sent'";
$result = mysql_query($update);
}
} //end for the "if(!$voted)"
// these are new queries to get the new values!
$newtotals = mysql_query("SELECT total_votes, total_value, used_ips FROM temp WHERE id='$id_sent' ")or die(" Error: ".mysql_error());
$numbers = mysql_fetch_assoc($newtotals);
$count = $numbers['total_votes'];//how many votes total
$current_rating = $numbers['total_value'];//total number of rating added together and stored
$tense = ($count==1) ? "vote" : "votes"; //plural form votes/vote
// $new_back is what gets 'drawn' on your page after a successful 'AJAX/Javascript' vote
ah ok here is the js file which seems to set those values, not sure if its a get or post thought
Code:
var xmlhttp
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
} catch (e) {
try {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
} catch (E) {
xmlhttp=false
}
}
@else
xmlhttp=false
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
xmlhttp=false
}
}
function myXMLHttpRequest() {
var xmlhttplocal;
try {
xmlhttplocal= new ActiveXObject("Msxml2.XMLHTTP")
} catch (e) {
try {
xmlhttplocal= new ActiveXObject("Microsoft.XMLHTTP")
} catch (E) {
xmlhttplocal=false;
}
}
if (!xmlhttplocal && typeof XMLHttpRequest!='undefined') {
try {
var xmlhttplocal = new XMLHttpRequest();
} catch (e) {
var xmlhttplocal=false;
alert('couldn\'t create xmlhttp object');
}
}
return(xmlhttplocal);
}
function sndReq(vote,id_num,ip_num,units) {
var theUL = document.getElementById('unit_ul'+id_num); // the UL
// switch UL with a loading div
theUL.innerHTML = '<div class="loading"></div>';
xmlhttp.open('get', 'rpc.php?j='+vote+'&q='+id_num+'&t='+ip_num+'&c='+units);
xmlhttp.onreadystatechange = handleResponse;
xmlhttp.send(null);
}
function handleResponse() {
if(xmlhttp.readyState == 4){
if (xmlhttp.status == 200){
var response = xmlhttp.responseText;
var update = new Array();
if(response.indexOf('|') != -1) {
update = response.split('|');
changeText(update[0], update[1]);
}
}
}
}
function changeText(div2show,text) {
var viewer = document.getElementById(div2show);
viewer.innerHTML = text;
}
/* =============================================================== */
var ratingAction = {
'a.rater' : function(element){
element.onclick = function(){
var parameterString = this.href.replace(/.*\?(.*)/, "$1"); // onclick="sndReq('j=1&q=2&t=127.0.0.1&c=5');
var parameterTokens = parameterString.split("&"); // onclick="sndReq('j=1,q=2,t=127.0.0.1,c=5');
var parameterList = new Array();
for (j = 0; j < parameterTokens.length; j++) {
var parameterName = parameterTokens[j].replace(/(.*)=.*/, "$1"); // j
var parameterValue = parameterTokens[j].replace(/.*=(.*)/, "$1"); // 1
parameterList[parameterName] = parameterValue;
}
var theratingID = parameterList['q'];
var theVote = parameterList['j'];
var theuserIP = parameterList['t'];
var theunits = parameterList['c'];
//for testing alert('sndReq('+theVote+','+theratingID+','+theuserIP+','+theunits+')'); return false;
sndReq(theVote,theratingID,theuserIP,theunits); return false;
}
}
};
Behaviour.register(ratingAction);
specifically this bit
Code:
function sndReq(vote,id_num,ip_num,units) {
var theUL = document.getElementById('unit_ul'+id_num); // the UL
// switch UL with a loading div
theUL.innerHTML = '<div class="loading"></div>';
xmlhttp.open('get', 'rpc.php?j='+vote+'&q='+id_num+'&t='+ip_num+'&c='+units);
xmlhttp.onreadystatechange = handleResponse;
xmlhttp.send(null);
}
i think that is what is setting those values?
cheers
Luke
__________________ Kernow Connect: Online Shopping, Price Comparison, Maximum Savings On Top UK Stores
Follow Us On: Twitter | Facebook
have sorted it now guys thanks, used firebug to check the js and it showed that one of the varibles was not defined, and defining it sorted the problem
cheers
Luke
__________________ Kernow Connect: Online Shopping, Price Comparison, Maximum Savings On Top UK Stores
Follow Us On: Twitter | Facebook
does anyone know how i can add a little animation next to the rating to show that its processing as sometimes it can take a few seconds to show the new rating, just so the user knows something is happening
function sndReq(vote,id_num,ip_num,units) {
var theUL = document.getElementById('unit_ul'+id_num); // the UL
// switch UL with a loading div
theUL.innerHTML = '<div class="loading"></div>';
xmlhttp.open('get', 'rpc.php?j='+vote+'&q='+id_num+'&t='+ip_num+'&c='+units);
xmlhttp.onreadystatechange = handleResponse;
xmlhttp.send(null);
}
which seems to suggest showing the loading image, so what is preventing it from loading?
any ideas
Luke
__________________ Kernow Connect: Online Shopping, Price Comparison, Maximum Savings On Top UK Stores
Follow Us On: Twitter | Facebook
2 Mlseim: It seems this information is not really correct. According to the Manual $_REQUEST is perfectly supported by PHP 5.3. But the directive request_order is introduced which describes the order in which PHP registers GET, POST and Cookie variables into the $_REQUEST array. Maybe you meant something different?