Renlok Posted October 7, 2006 Share Posted October 7, 2006 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 More sharing options...
Barand Posted October 7, 2006 Share Posted October 7, 2006 I thought it was your intention to get the average rating$rate_query = "SELECT AVG(ratingValue) FROM rating WHERE URL = '$URL'"; Link to comment https://forums.phpfreaks.com/topic/23233-adding-rating-value-problems/#findComment-105419 Share on other sites More sharing options...
Renlok Posted October 7, 2006 Author Share Posted October 7, 2006 oops :D urm yes but thats not what my main consern is now now its the bottom peice of text. Link to comment https://forums.phpfreaks.com/topic/23233-adding-rating-value-problems/#findComment-105443 Share on other sites More sharing options...
Barand Posted October 7, 2006 Share Posted October 7, 2006 You mean where your form method is 'POST' and you are using[code]$rate=$_GET['rate'];$url=$_GET['url'];[/code] Link to comment https://forums.phpfreaks.com/topic/23233-adding-rating-value-problems/#findComment-105444 Share on other sites More sharing options...
Renlok Posted October 7, 2006 Author Share Posted October 7, 2006 yeah oh and i missed out a bunch of . and ' in the form works now. Link to comment https://forums.phpfreaks.com/topic/23233-adding-rating-value-problems/#findComment-105445 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.