Jump to content

Adding rating value problems


Renlok

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]
Link to comment
https://forums.phpfreaks.com/topic/23233-adding-rating-value-problems/
Share on other sites

Archived

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

×
×
  • Create New...

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.