Unstoppable Domains โ€” Expired Auctions

PHP Help: Ratings

SpaceshipSpaceship
Watch

flishess

Established Member
Impact
6
submitrating.php:

Code:
<? 

if($_POST['submit'])
{
   include("config.php");

   $rating = mysql_real_escape_string($_POST['rating']);

   $result=MYSQL_QUERY("INSERT INTO gamepage (rating)".
      "VALUES ('$rating')"); 

   echo "Query Finished"; 
Header ("Location: ./rate.php");
}
?>

index.php (where rate drop down box displays at
Code:
include "rate.php";

Code:
<?
include "config.php";

if (is_numeric($_GET['id']))
{
    $id = $_GET['id'];
    $result = mysql_query("SELECT platform,description,id,title,release_us,msrp,buylink,developer,publisher,esrb,genre,boxart FROM `gamepage` where id = $id") or die(mysql_error
        ());
    while ($row = mysql_fetch_array($result))
    {
        $title = $row["title"];
        $description = $row["description"];
        $cat = $row['platform'];
        $release_us = $row['release_us'];
        $boxart = $row['boxart'];
        $msrp = $row['msrp'];
        $buylink = $row['buylink'];
        $developer = $row['developer'];
        $publisher = $row['publisher'];
        $esrb = $row['esrb'];
        $genre = $row['genre'];

        echo ("<p>$title</p>");
        echo ("<p>$cat");
        echo "<p><img src='$boxart'></p>";
        echo stripcslashes ("<p>$description</p>");
        echo ("<p>$release_us</p>");
        echo ("<p>$msrp</p>");
        echo "<p><a href='$buylink'>Buy Now</a></p>";
        echo ("<p>$developer</p>");
        echo ("<p>$publisher</p>");
        echo ("<p>$esrb</p>");
        echo ("<p>$genre</p>");
[COLOR=Red]include "rate.php";[/COLOR]
}
    echo nl2br("<p><a href='" . $_SERVER['SCRIPT_NAME'] . "'>Back</a></p>");
} else
{
    $result = mysql_query("SELECT id,title FROM `gamepage` ORDER BY title") or die(mysql_error());
    while ($row = mysql_fetch_array($result))
    {
        $title = $row["title"];
        $id = $row["id"];
        echo "<p><a href='index.php?id=$id'>$title</a></p>";
    }
}
?>

rate.php:

Code:
<?
include("config.php");
?>
<html>
<form method="post" action="submitrating.php">

<h3>Rate Game:</h3>
<select name="rating">
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
  <option value="4">4</option>
  <option value="5">5</option>
  <option value="6">6</option>
  <option value="7">7</option>
  <option value="8">8</option>
  <option value="9">9</option>
  <option value="10">10</option>
</select>
<br>
<br>
<INPUT TYPE="submit" name="submit" value="submit">
</form>
</html>

I am trying to get the rating to write to the database according to the game that is being rated, this needs a little more coding to make it write to the correct game.

Code:
   $rating = mysql_real_escape_string($_POST['rating']);

   $result=MYSQL_QUERY("INSERT INTO gamepage (rating)".
      "VALUES ('$rating')");

Can someone help please?

here is the url:

www.getgamereviews.com if you click on a game title you will see where the drop down box displays.
 
Last edited:
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Unstoppable Domains โ€” AI StorefrontUnstoppable Domains โ€” AI Storefront
For the submitrating.php file you're going to need to carry the game title or id variable over so you could have:

insert into databse (rating) values rating where title = $title

however you may want to do 'update' instead of insert?

Something like

Code:
$update = "UPDATE gamepage SET rating= '$rating' WHERE id= $id";
		$result = mysql_query($update);

Though from just the code provided it looks like the script will only use the latest vote as its rating for the game, so if user 1 rates a 10 and user 2 rates a 4 the game will reflect a 4 rating, so you're going to need to store a total number of votes column as well. So on the submitrating.php file you could put something like this

Code:
$query = "SELECT votes, rating FROM gamepage WHERE id = $id";
$sql = mysql_query($query);
$yup = mysql_fetch_assoc($sql);

$votes = $yup['votes'];
$ratings = $yup['rating'];

$votes++;

$rate = $rating + $ratings;

$yes = "UPDATE gamepage
              SET votes = $votes,
               ratings = $rate
         WHERE id = $id";

$yer = mysql_query($yes);

Then if you display the rating anywhere on the page you simply select votes & rating for the database and divide the two and you'll have the average user rating of that particular game.

And I'm sure as you know my code might be missing a character or two or could be totally off base, I'm just trying to help. :) I couldn't get your page to load so my apologies if none of this applies and is all just jibberish.

Thanks,
 
0
•••
I appreciate the help Edit - I will see what I can do with this, thanks.
 
0
•••
Dynadot โ€” .com TransferDynadot โ€” .com Transfer
Appraise.net
Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
NameMaxi - Your Domain Has Buyers
DomDB
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back