Jump to content


Photo

Adding rating value problems


  • Please log in to reply
4 replies to this topic

#1 Renlok

Renlok
  • Members
  • PipPipPip
  • Advanced Member
  • 258 posts
  • Locationnewbury

Posted 07 October 2006 - 12:26 AM

This is leading on from my lsat post http://www.phpfreaks...c,110085.0.html

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.
$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>';
}

this is the php file 'rate.php'
<?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();
?>


#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 07 October 2006 - 08:05 AM

I thought it was your intention to get the average rating

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

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 Renlok

Renlok
  • Members
  • PipPipPip
  • Advanced Member
  • 258 posts
  • Locationnewbury

Posted 07 October 2006 - 09:19 AM

oops  :D urm yes but thats not what my main consern is now now its the bottom peice of text.

#4 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 07 October 2006 - 09:23 AM

You mean where your form method is 'POST' and you are using
$rate=$_GET['rate'];
$url=$_GET['url'];

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#5 Renlok

Renlok
  • Members
  • PipPipPip
  • Advanced Member
  • 258 posts
  • Locationnewbury

Posted 07 October 2006 - 09:26 AM

yeah oh and i missed out a bunch of . and ' in the form works now.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users