Jump to content

Archived

This topic is now archived and is closed to further replies.

Renlok

Adding rating value problems

Recommended Posts

This is leading on from my lsat post [url=http://www.phpfreaks.com/forums/index.php/topic,110085.0.html]http://www.phpfreaks.com/forums/index.php/topic,110085.0.html[/url]

OK here it is this is surposed to get a users rating for a url in the database and enter both the url and the rating in a table named rating.

This is the entry form of the rating.
[code]$URL = ($row['url']);
$rate_query = "SELECT ratingValue FROM rating WHERE URL = '$URL'";
$rate_result = $db->query($rate_query);
$row = $rate_result->fetch_row();
$avg = $row[0];
echo '<br><u>Rating:</u> '.$avg.'<br>';
echo 'Rate This Site: ';
echo '<form name="$URL" form action="rate.php" method="post" target="_blank" form>'.
        '<select name="rate">'.
            '<option value="one">1</option>'.
            '<option value="two">2</option>'.
            '<option value="three">3</option>'.
            '<option value="four">4</option>'.
            '<option value="five">5</option>'.
            '<option value="six">6</option>'.
            '<option value="seven">7</option>'.
            '<option value="eight">8</option>'.
            '<option value="nine">9</option>'.
            '<option value="ten">10</option>'.
        '</select>'.
        '<input name="url" type="hidden" value="$URL" size="13" maxlength="125">'.
      '<input type="submit" value="Submit">'.
    '</form>';
}[/code]

this is the php file 'rate.php'
[code]<?php
  // create short variable names
  $rate=$_GET['rate'];
  $url=$_GET['url'];

  if (!get_magic_quotes_gpc())
  {
    $rate = addslashes($rate);
    $url = addslashes($url);
  }

  @ $db = new mysqli('****', '****', '****', '****');  // not actual values

  if (mysqli_connect_errno())
  {
    echo 'Error: Could not connect to database.  Please try again later.';
    exit;
  }

  $query = "insert into rating (ratingValue, URL) values
            ('".$rate."', '".$url."')";
  $result = $db->query($query) or die ($db->error);
  if ($result)
      echo  $db->affected_rows.' You have rated '.$url.'as a '.$rate;

  $db->close();
?>[/code]

Share this post


Link to post
Share on other sites
I thought it was your intention to get the average rating

$rate_query = "SELECT AVG(ratingValue) FROM rating WHERE URL = '$URL'";

Share this post


Link to post
Share on other sites
oops  :D urm yes but thats not what my main consern is now now its the bottom peice of text.

Share this post


Link to post
Share on other sites
You mean where your form method is 'POST' and you are using
[code]
$rate=$_GET['rate'];
$url=$_GET['url'];
[/code]

Share this post


Link to post
Share on other sites
yeah oh and i missed out a bunch of . and ' in the form works now.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.