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
Help with rating scripts
Old 02-13-2009, 09:08 PM Help with rating scripts
moatist's Avatar
Skilled Talker

Posts: 64
Trades: 0
Hey,

This problem should be easy to fix, I just wanted to see if anyone had a quick solution to my problem.

Here's the problem:

When a user rates, the script prints a mesage stating that the user has rated. When a user does not select a rating and still clicks on the submit button, he SHOULD get a message stating that he has not rated. This message is not displaying and I'm not sure why.

Here is the code I have so far:

Code:
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
///////////////results.txt updater///////////////////////
$rate = $_POST["rate"];
if ($rate) {
 if ($rate>0) {
 $File = "results.txt";
 $Handle = fopen($File, 'a');
 $Data = "$rate\n"; 
 fwrite($Handle, $Data);
 print "<small>Thanks for the rating!</small>"; 
 fclose($Handle); 
 }
 
 elseif ($rate==0) { //
 print "<small>Please select a rating.</small>"; //this is the problem area
 } //
}

//////////////////////Rating form//////////////////////////////////////////
echo "<form name=\"rating_form\" method=\"post\">";
echo "<select name=\"rate\">";
echo "<option value=\"0\">--rate--</option>";
echo  "<option value=\"100\">5</option>";
echo  "<option value=\"80\">4</option>";
echo   "<option value=\"60\">3</option>";
echo   "<option value=\"40\">2</option>";
echo   "<option value=\"20\">1</option>";
echo "</select>";
echo "<input name=\"submit\" type=\"submit\" value=\"Submit\">";
echo    "</form>";
echo "<table width=\"200\" border=\"1\" bordercolor=\"#666666\" cellpadding=\"0\" cellspacing=\"0\">";
echo "<tr>";
echo " <td style=\"$is_green_fix\" width=\"$result%\" height=\"15\"></td>";
echo  "<td width=\"$width_white\" style=\"$no_green_fix\"></td>";
echo "</tr>";
echo "</table>";
?>
</body>
</html>
Thanks for the help,
Moatist
moatist is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-13-2009, 10:45 PM Re: Help with rating scripts
Corey's Avatar
Super Talker

Latest Blog Post:
Pre-Pop Offers
Posts: 142
Name: Corey
Location: United States
Trades: 0
Try this:

PHP Code:
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
    
/* results.txt updater */
    
$rate $_POST["rate"];
    if(
$rate 0) {
        
$File "results.txt";
        
$Handle fopen($File'a');
        
$Data "$rate\n"
        
fwrite($Handle$Data);
        print 
"<small>Thanks for the rating!</small>"
        
fclose($Handle); 
    }
     elseif (
$rate == 0) {
        print 
"<small>Please select a rating.</small>";
    }

/* Rating form */
echo "<form name=\"rating_form\" method=\"post\">";
echo 
"<select name=\"rate\">";
echo 
"<option value=\"0\">--rate--</option>";
echo  
"<option value=\"100\">5</option>";
echo  
"<option value=\"80\">4</option>";
echo   
"<option value=\"60\">3</option>";
echo   
"<option value=\"40\">2</option>";
echo   
"<option value=\"20\">1</option>";
echo 
"</select>";
echo 
"<input name=\"submit\" type=\"submit\" value=\"Submit\">";
echo    
"</form>";
echo 
"<table width=\"200\" border=\"1\" bordercolor=\"#666666\" cellpadding=\"0\" cellspacing=\"0\">";
echo 
"<tr>";
echo 
" <td style=\"$is_green_fix\" width=\"$result%\" height=\"15\"></td>";
echo  
"<td width=\"$width_white\" style=\"$no_green_fix\"></td>";
echo 
"</tr>";
echo 
"</table>";
?>
</body>
</html>
__________________

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

Phone: 888-400-4359 || AIM S/N: CoreyPeerFly
Launched in 2008 - Daily Payments by PayPal
Corey is offline
Reply With Quote
View Public Profile Visit Corey's homepage!
 
Old 02-14-2009, 05:17 PM Re: Help with rating scripts
moatist's Avatar
Skilled Talker

Posts: 64
Trades: 0
All right,

I fixed that problem but now I'm having bigger problems.

I figured out how to detect if someone has rated before by their IP address. This works fine. The problem is that I am not sure how to add the ratings up (I'll get the overall average later). The IPs/ratings are stored in a text file in the format ip:rating
69.157.243.112:60
69.157.243.112:80
69.157.243.112:20



Here's the code (I updated it):

PHP Code:
<html>
<head>
<title>Armor Films rating script</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php
///////////////IP check//////////////////////////////////
if (file_exists("results.txt")) {
$ip getenv('REMOTE_ADDR');
$old_results file('results.txt');
$already_rated false;
      
      foreach (
$old_results as $value_1) {
      
$one_rate explode(':',$value_1);
      
          if (
$ip == $one_rate[0]) {
           
$already_rated true;     
              }
    }
}

///////////////results.txt updater///////////////////////
$rate $_POST["rate"];
$users_ip $_SERVER['REMOTE_ADDR'];

if (
$rate && $already_rated != true) {

    if (
$rate 0) {
    
$File "results.txt";
    
$Handle fopen($File'a');
    
$Data "$users_ip:$rate\n"
    
fwrite($Handle$Data);  
    print 
"<small>Thanks for the rating!</small>";
    
fclose($Handle); 
    }
    
}

elseif (
$rate && $already_rated true) {
    print 
"<small>You have already rated.</small>";
    }


////////////value handler////////////////////////////////
$value_file fopen("results.txt""r");

while(!
feof($value_file)) {
    
$line fgets($value_file);
    
$rating_values substr($line, -3);
        print 
$rating_values;
        }
                

fclose($value_file);

echo 
$total;
//////////////////////Rating form//////////////////////////////////////////
echo "<form name=\"rating_form\" method=\"post\">";
echo    
"<select name=\"rate\">";
echo    
"<option value=\"0\">--rate--</option>";
echo     
"<option value=\"100\">5</option>";
echo     
"<option value=\"80\">4</option>";
echo      
"<option value=\"60\">3</option>";
echo      
"<option value=\"40\">2</option>";
echo      
"<option value=\"20\">1</option>";
echo    
"</select>";
echo    
"<input name=\"submit\" type=\"submit\" value=\"Submit\">";
echo    
"</form>";

echo 
"<table width=\"200\" border=\"1\" bordercolor=\"#666666\" cellpadding=\"0\" cellspacing=\"0\">";
echo    
"<tr>";
echo    
"    <td style=\"$is_green_fix\" width=\"$result%\" height=\"15\"></td>";
echo        
"<td width=\"$width_white\" style=\"$no_green_fix\"></td>";
echo    
"</tr>";
echo 
"</table>";
?>
</body>
</html>

Thanks,
Moatist
moatist is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Help with rating scripts
 

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.12106 seconds with 12 queries