View Single Post
Old 12-21-2007, 03:31 PM   #9 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

Quote:
Originally Posted by Village Idiot View Post
Something like this should work
form.html
HTML Code:
 <style type="text/css">
 input.ratingsnstuff {
   background:url('rate/default.png') no-repeat;
   border:none;
   width:16px;
   height:16px;
   margin:1px;
   cursor: pointer;
   }
   
    input:hover.ratingsnstuff {
   background:url('rate/default_hover.png') no-repeat;
   border:none;
   width:16px;
   height:16px;
   margin:1px;
   cursor: pointer;
   }
   </style>
   
<form class="ratingsnstuff" action="action.php" method="post">
<input class="ratingsnstuff" name="star"  type="button" value="1">
<input class="ratingsnstuff" name="star"  type="button" value="2">
<input class="ratingsnstuff" name="star"  type="button" value="3">
<input class="ratingsnstuff" name="star"  type="button" value="4">
<input class="ratingsnstuff" name="star"  type="button" value="5">
</form>
Note the values I put in there, without that, how does the database know whats been rated? Also, give then the same name, only one can be clicked after all.

action.php
PHP Code:
 <?php

$dbhost 
"localhost";
$dbuser "root";
$dbpass "";
$database "rates";

mysql_connect($dbhost$dbuser$dbpass) or die(mysql_error());
mysql_select_db($database) or die(mysql_error());


$rateid intval($_REQUEST['rateid']);
$rating $_POST["star"];
//lets say the ratings table has two fields, ID (primary key, auto_incriment) and rating.
$query mysql_query("Insert into db_ratings VALUES (NULL,'$rating')") OR die(mysql_error());

echo 
"rating sucessful";
?>
This doesnt need to be in a function, and the rating is all one name so no need for the foreach loop. This may not be valid HTML however.

Insetad of two if statements, just tell the query do die the mysql error if unsuccessful and echo if it passes (Die ends the page, should be taken out after debugging)

Putting a return statement outside of a function will generate a syntax error.

Wow, you took my script and simplified it! Great; thanks man!

UPDATE: It still says Rated Successful even though I have not submitted one of the stars yet.
Orc is offline  
Reply With Quote