Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-04-2010, 10:52 PM   PM User | #1
LJackson
Senior Coder

 
Join Date: Jun 2008
Location: Cornwall
Posts: 1,973
Thanks: 289
Thanked 12 Times in 12 Posts
LJackson is on a distinguished road
Exclamation 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|
and here is my php file
PHP Code:
header("Cache-Control: no-cache");
header("Pragma: nocache");

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==$added=$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 >= && $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

$new_back = array();

$new_back[] .= '<ul class="unit-rating" style="width:'.$units*$rating_unitwidth.'px;">';
$new_back[] .= '<li class="current-rating" style="width:'.@number_format($current_rating/$count,2)*$rating_unitwidth.'px;">Current rating.</li>';
$new_back[] .= '<li class="r1-unit">1</li>';
$new_back[] .= '<li class="r2-unit">2</li>';
$new_back[] .= '<li class="r3-unit">3</li>';
$new_back[] .= '<li class="r4-unit">4</li>';
$new_back[] .= '<li class="r5-unit">5</li>';
$new_back[] .= '<li class="r6-unit">6</li>';
$new_back[] .= '<li class="r7-unit">7</li>';
$new_back[] .= '<li class="r8-unit">8</li>';
$new_back[] .= '<li class="r9-unit">9</li>';
$new_back[] .= '<li class="r10-unit">10</li>';
$new_back[] .= '</ul>';
$new_back[] .= '<p class="voted">'.$id_sent.'. Rating: <strong>'.@number_format($sum/$added,1).'</strong>/'.$units.' ('.$count.' '.$tense.' cast) ';
$new_back[] .= '<span class="thanks">Thanks for voting!</span></p>';

$allnewback join("\n"$new_back);

// ========================

//name of the div id to be updated | the html that needs to be changed
$output "unit_long$id_sent|$allnewback";
echo 
$output
does this look correct for php 5.3?

thanks all
Luke
__________________
Kernow Connect: Online Shopping, Price Comparison, Maximum Savings On Top UK Stores
Follow Us On: Twitter | Facebook
LJackson is offline   Reply With Quote
Old 02-04-2010, 11:15 PM   PM User | #2
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,042
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
$_REQUEST is no longer supported.

You have to specify either $_GET or $_POST, depending on which it is supposed to be.
mlseim is offline   Reply With Quote
Old 02-04-2010, 11:19 PM   PM User | #3
LJackson
Senior Coder

 
Join Date: Jun 2008
Location: Cornwall
Posts: 1,973
Thanks: 289
Thanked 12 Times in 12 Posts
LJackson is on a distinguished road
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
LJackson is offline   Reply With Quote
Old 02-04-2010, 11:33 PM   PM User | #4
LJackson
Senior Coder

 
Join Date: Jun 2008
Location: Cornwall
Posts: 1,973
Thanks: 289
Thanked 12 Times in 12 Posts
LJackson is on a distinguished road
$_GET seems to do the same as $_request.

the odd thing is that the rating is being counted but not being shown unless i press the refresh button then the star value is shown.

any other ideas mate
cheers
Luke
__________________
Kernow Connect: Online Shopping, Price Comparison, Maximum Savings On Top UK Stores
Follow Us On: Twitter | Facebook
LJackson is offline   Reply With Quote
Old 02-04-2010, 11:33 PM   PM User | #5
PappaJohn
Senior Coder

 
Join Date: Apr 2007
Location: Quakertown PA USA
Posts: 1,028
Thanks: 1
Thanked 125 Times in 123 Posts
PappaJohn will become famous soon enough
Code:
xmlhttp.open('get', 'rpc.php?j='+vote+'&q='+id_num+'&t='+ip_num+'&c='+units);
It's sending the request via GET.
__________________
John
PappaJohn is offline   Reply With Quote
Old 02-04-2010, 11:41 PM   PM User | #6
LJackson
Senior Coder

 
Join Date: Jun 2008
Location: Cornwall
Posts: 1,973
Thanks: 289
Thanked 12 Times in 12 Posts
LJackson is on a distinguished road
cheers John! have updated that now.

still wont show the ratings as the user selects them

cheers
__________________
Kernow Connect: Online Shopping, Price Comparison, Maximum Savings On Top UK Stores
Follow Us On: Twitter | Facebook

Last edited by LJackson; 02-05-2010 at 02:51 PM..
LJackson is offline   Reply With Quote
Old 02-04-2010, 11:42 PM   PM User | #7
MattF
Senior Coder

 
Join Date: Jul 2009
Location: South Yorkshire, England
Posts: 2,322
Thanks: 6
Thanked 304 Times in 303 Posts
MattF will become famous soon enoughMattF will become famous soon enough
Quote:
Originally Posted by mlseim View Post
$_REQUEST is no longer supported.
Do you have a link to where that's mentioned? Can't find any reference to it being deprecated on the php site.

http://uk.php.net/manual/en/reserved...es.request.php
MattF is offline   Reply With Quote
Old 02-05-2010, 01:42 AM   PM User | #8
bdl
Regular Coder

 
Join Date: Apr 2007
Location: Camarillo, CA US
Posts: 590
Thanks: 4
Thanked 83 Times in 82 Posts
bdl is an unknown quantity at this point
@MattF> The page you've linked specifies that 5.3.0 changed the order, but I don't see anything mentioning that either.
bdl is offline   Reply With Quote
Old 02-05-2010, 01:44 PM   PM User | #9
LJackson
Senior Coder

 
Join Date: Jun 2008
Location: Cornwall
Posts: 1,973
Thanks: 289
Thanked 12 Times in 12 Posts
LJackson is on a distinguished road
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
LJackson is offline   Reply With Quote
Old 02-05-2010, 02:37 PM   PM User | #10
LJackson
Senior Coder

 
Join Date: Jun 2008
Location: Cornwall
Posts: 1,973
Thanks: 289
Thanked 12 Times in 12 Posts
LJackson is on a distinguished road
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

i have this in my css
Code:
.loading {
	height: 20px;
	background: url('../images/working.gif') 50% 50% no-repeat;
	}
but can see where the loading class is being used, or maybe its not?

i have tried adding it but no image shows
PHP Code:
'<div class="loading"></div>'
where should i place it?

thanks
Luke
__________________
Kernow Connect: Online Shopping, Price Comparison, Maximum Savings On Top UK Stores
Follow Us On: Twitter | Facebook

Last edited by LJackson; 02-05-2010 at 02:39 PM..
LJackson is offline   Reply With Quote
Old 02-05-2010, 02:43 PM   PM User | #11
LJackson
Senior Coder

 
Join Date: Jun 2008
Location: Cornwall
Posts: 1,973
Thanks: 289
Thanked 12 Times in 12 Posts
LJackson is on a distinguished road
ok found this in the js file
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);	
}
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
LJackson is offline   Reply With Quote
Old 02-05-2010, 03:12 PM   PM User | #12
bdl
Regular Coder

 
Join Date: Apr 2007
Location: Camarillo, CA US
Posts: 590
Thanks: 4
Thanked 83 Times in 82 Posts
bdl is an unknown quantity at this point
Please ask a moderator to merge this new topic into a new thread in the JavaScript forum.
bdl is offline   Reply With Quote
Old 02-05-2010, 03:42 PM   PM User | #13
SKDevelopment
Regular Coder

 
Join Date: Mar 2006
Posts: 238
Thanks: 3
Thanked 37 Times in 37 Posts
SKDevelopment has a little shameless behaviour in the past
Quote:
Originally Posted by mlseim View Post
$_REQUEST is no longer supported.
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?

I am sorry to the OP for the off-topic.
__________________
PHP Programmer

Last edited by SKDevelopment; 02-05-2010 at 03:48 PM..
SKDevelopment is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:41 AM.


Advertisement
Log in to turn off these ads.