Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
PHP voting script help.
Old 07-17-2006, 12:13 PM PHP voting script help.
dismaldonkey's Avatar
Boo's daddy

Posts: 286
Location: Tunbridge Wells
Trades: 0
As will be made very evidently clear here, I am absolutely hopeless on PHP.

I am trying to install a voting script, but seem to be getting nowhere fast. I have mangaed (just about) to have it actually show up on the page, but when i try to vote nothing happens.

Here is the code I have on the page:

Code:
<div class="hreview"><form method="post" action="/ghosts1a.php">
<h3 class="item">Rate <span class="fn">this photo</span></h3><div><span  class="rating">
<img src="rater/img/00star.gif?x=99843644bbaa94f3c448.12039862" alt="0 stars" /> 
Ave. rating: 0</span> from <span class="reviewcount"> 0 votes</span>.</div><div><label for="rate5_1">
<input type="radio" value="5" name="rating_1[]" id="rate5_1" />Excellent</label><label for="rate4_1">
<input type="radio" value="4" name="rating_1[]" id="rate4_1" />Very Good</label><label for="rate3_1">
<input type="radio" value="3" name="rating_1[]" id="rate3_1" />Good</label><label for="rate2_1">
<input type="radio" value="2" name="rating_1[]" id="rate2_1" />Fair</label><label for="rate1_1">
<input type="radio" value="1" name="rating_1[]" id="rate1_1" />Poor</label><input type="hidden" name="rs_id" value="1" />
<input type="submit" name="rate1" value="Rate" /></div></form></div>
I am almost certainly sure I have the info wrong in the top line, action="/ghosts1a.php" but am not sure what else it should be

Here a link to the page as it is now.
http://www.truthunknown.com/ghosts1a.php

Here is the rest of the code, the main php file. (rater.php)


Code:
<?

// User settings
$rater_ip_voting_restriction = false; // restrict ip address voting (true or false)
$rater_ip_vote_qty=4; // how many times an ip address can vote
$rater_already_rated_msg="You have already rated this item. You were allowed ".$rater_ip_vote_qty." vote(s).";
$rater_not_selected_msg="You have not selected a rating value.";
$rater_thankyou_msg="Thankyou for voting.";
$rater_generic_text="this item"; // generic item text
$rater_end_of_line_char="\n"; // may want to change for different operating systems



if(!isset($rater_id)) $rater_id=1;
if(!isset($rater_item_name)) $rater_item_name=$rater_generic_text;


// DO NOT MODIFY BELOW THIS LINE
$rater_filename='item_'.$rater_id.".rating";
$rater_rating=0;
$rater_stars="";
$rater_stars_txt="";
$rater_rating=0;
$rater_votes=0;
$rater_msg="";

// Rating action
if(isset($_REQUEST["rate".$rater_id])){
 if(isset($_REQUEST["rating_".$rater_id])){
  while(list($key,$val)=each($_REQUEST["rating_".$rater_id])){
   $rater_rating=$val;
  }
  $rater_ip = getenv("REMOTE_ADDR"); 
  $rater_file=fopen($rater_filename,"a+");
  $rater_str="";
  $rater_str = rtrim(fread($rater_file, 1024*8),$rater_end_of_line_char);
  if($rater_str!=""){
   if($rater_ip_voting_restriction){
    $rater_data=explode($rater_end_of_line_char,$rater_str);
	$rater_ip_vote_count=0;
    foreach($rater_data as $d){
	 $rater_tmp=explode("|",$d);
	 $rater_oldip=str_replace($rater_end_of_line_char,"",$rater_tmp[1]);
	 if($rater_ip==$rater_oldip){
	  $rater_ip_vote_count++;
	 }
    }
	if($rater_ip_vote_count > ($rater_ip_vote_qty - 1)){
     $rater_msg=$rater_already_rated_msg;
	}else{
     fwrite($rater_file,$rater_rating."|".$rater_ip.$rater_end_of_line_char);
     $rater_msg=$rater_thankyou_msg;
	}
   }else{
    fwrite($rater_file,$rater_rating."|".$rater_ip.$rater_end_of_line_char);
    $rater_msg=$rater_thankyou_msg;
   }
  }else{
   fwrite($rater_file,$rater_rating."|".$rater_ip.$rater_end_of_line_char);
   $rater_msg=$rater_thankyou_msg;
  }
  fclose($rater_file);
 }else{
  $rater_msg=$rater_not_selected_msg;
 }
}

// Get current rating
if(is_file($rater_filename)){
 $rater_file=fopen($rater_filename,"r");
 $rater_str="";
 $rater_str = fread($rater_file, 1024*8);
 if($rater_str!=""){
  $rater_data=explode($rater_end_of_line_char,$rater_str);
  $rater_votes=count($rater_data)-1;
  $rater_sum=0;
  foreach($rater_data as $d){
   $d=explode("|",$d);
   $rater_sum+=$d[0];
  }
  $rater_rating=number_format(($rater_sum/$rater_votes), 2, '.', '');
 }
 fclose($rater_file);
}else{
 $rater_file=fopen($rater_filename,"w");
 fclose($rater_file);
}

// Assign star image
if ($rater_rating <= 0  ){$rater_stars = "./img/00star.gif";$rater_stars_txt="Not Rated";}
if ($rater_rating >= 0.5){$rater_stars = "./img/05star.gif";$rater_stars_txt="0.5";}
if ($rater_rating >= 1  ){$rater_stars = "./img/1star.gif";$rater_stars_txt="1";}
if ($rater_rating >= 1.5){$rater_stars = "./img/15star.gif";$rater_stars_txt="1.5";}
if ($rater_rating >= 2  ){$rater_stars = "./img/2star.gif";$rater_stars_txt="2";}
if ($rater_rating >= 2.5){$rater_stars = "./img/25star.gif";$rater_stars_txt="2.5";}
if ($rater_rating >= 3  ){$rater_stars = "./img/3star.gif";$rater_stars_txt="3";}
if ($rater_rating >= 3.5){$rater_stars = "./img/35star.gif";$rater_stars_txt="3.5";}
if ($rater_rating >= 4  ){$rater_stars = "./img/4star.gif";$rater_stars_txt="4";}
if ($rater_rating >= 4.5){$rater_stars = "./img/45star.gif";$rater_stars_txt="4.5";}
if ($rater_rating >= 5  ){$rater_stars = "./img/5star.gif";$rater_stars_txt="5";}


// Output
echo '<div class="hreview">';
echo '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
echo '<h3 class="item">Rate <span class="fn">'.$rater_item_name.'</span></h3>';
echo '<div>';
echo '<span  class="rating"><img src="'.$rater_stars.'?x='.uniqid((double)microtime()*1000000,1).'" alt="'.$rater_stars_txt.' stars" /> Ave. rating: '.$rater_stars_txt.'</span> from <span class="reviewcount"> '.$rater_votes.' votes</span>.';
echo '</div>';
echo '<div>';
echo '<label for="rate5_'.$rater_id.'"><input type="radio" value="5" name="rating_'.$rater_id.'[]" id="rate5_'.$rater_id.'" />Excellent</label>';
echo '<label for="rate4_'.$rater_id.'"><input type="radio" value="4" name="rating_'.$rater_id.'[]" id="rate4_'.$rater_id.'" />Very Good</label>';
echo '<label for="rate3_'.$rater_id.'"><input type="radio" value="3" name="rating_'.$rater_id.'[]" id="rate3_'.$rater_id.'" />Good</label>';
echo '<label for="rate2_'.$rater_id.'"><input type="radio" value="2" name="rating_'.$rater_id.'[]" id="rate2_'.$rater_id.'" />Fair</label>';
echo '<label for="rate1_'.$rater_id.'"><input type="radio" value="1" name="rating_'.$rater_id.'[]" id="rate1_'.$rater_id.'" />Poor</label>';
echo '<input type="hidden" name="rs_id" value="'.$rater_id.'" />';
echo '<input type="submit" name="rate'.$rater_id.'" value="Rate" />';
echo '</div>';
if($rater_msg!="") echo "<div>".$rater_msg."</div>";
echo '</form>';
echo '</div>';

?>
If anyone can help me to get this working they will have my eternal gratitude.

Cheers
__________________

Please login or register to view this content. Registration is FREE



Please login or register to view this content. Registration is FREE
dismaldonkey is offline
Reply With Quote
View Public Profile Visit dismaldonkey's homepage!
 
 
Register now for full access!
Old 07-17-2006, 08:25 PM Re: PHP voting script help.
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
what kind of problem are you having? Is the rater.php script executing?

I don't know if this has anything to do do with your problem, but either change your form action to:

action="./ghosts1a.php"

or

action="ghosts1a.php"
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 07-20-2006, 05:56 AM Re: PHP voting script help.
dismaldonkey's Avatar
Boo's daddy

Posts: 286
Location: Tunbridge Wells
Trades: 0
Still cant get the ****** thing to work.



Anyone help.......Please!
__________________

Please login or register to view this content. Registration is FREE



Please login or register to view this content. Registration is FREE
dismaldonkey is offline
Reply With Quote
View Public Profile Visit dismaldonkey's homepage!
 
Old 07-20-2006, 09:59 AM Re: PHP voting script help.
mad_willsy's Avatar
Super Spam Talker

Latest Blog Post:
R&R Catering Hire Testimonial
Posts: 805
Name: Will Craig
Location: Cheltenham, Gloucestershire, UK
Trades: 0
Try a different script!
__________________
Wont :P

Please login or register to view this content. Registration is FREE
mad_willsy is offline
Reply With Quote
View Public Profile Visit mad_willsy's homepage!
 
Old 07-20-2006, 10:30 AM Re: PHP voting script help.
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
It doesn't appear that the item_X.rating file is being created. Check the permissions at the directory where it is supposed to be stored to make sure it allows php to modify/create files there.
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to PHP voting script help.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.50451 seconds with 12 queries