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] Quote Link to comment 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'"; Quote Link to comment 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. Quote Link to comment 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] Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.