I have a page that displays the data of a mysql entry, depending on the link the user clicked ($pagename).. Im wondering how I can create a very basic rating system, that will consist of a form with drop down options of 1 to 5, and when the user submits this value, it posts the data to the corresponding ID of the entry thats currently on the page.
<?php
$pagename = $_GET['name'];
$sql = "SELECT * FROM tblCocktail WHERE name = '$pagename' LIMIT 1";
/*$sql = sprintf(%sql, mysql_real_escape_string($pagename));*/
$result = mysql_query($sql);
if(!$result) {
// error occured
}
$data = mysql_fetch_assoc($result);
echo "<p class=\"paratitle\">".$data["name"]." </p>";
echo "<p class=\"paratitle3\">".$data["howto"]." </p>";
echo "<p class=\"paratitle2\">".$data["ingredient1"]." </p>";
echo "<p class=\"paratitle3\">".$data["quantity1"]." </p>";
echo "<p class=\"paratitle2\">".$data["ingredient2"]." </p>";
echo "<p class=\"paratitle3\">".$data["quantity2"]." </p>";
echo "<p class=\"paratitle2\">".$data["ingredient3"]." </p>";
echo "<p class=\"paratitle3\">".$data["quantity3"]." </p>";
echo "<p class=\"dateadded\">".$data["dateadded"]." </p>";
?>
</div>
</div>
<div id="cont2">
<div id="contentwrap">
<form method="POST" action="addrating.php" >
<input type="hidden" name="cocktailID" value="<?=$data["id"]?>">
<select id="ratinglevel" name="ratinglevel">
<option></option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
<input type="submit" value="submit" />
</form>
addrating.php:
<?php
mysql_select_db("mwheywood", $con);
//insert cocktail details
$sql="INSERT INTO tblRating (cocktailID, value, counter)
VALUES
('$_POST[id]','$_POST[ratinglevel]','1'";
if (!mysql_query($sql,$con))
{
die('Error: you fail at life' . mysql_error());
}
echo "<p>Thanks for voting</p>"
?>
the table I want to save the rating into is linked via “cocktailID” to the data that is being echo’d in the above code.
and the table structure of “tblRating” is: ratingID, cocktailID, value, counter..
I therefore want the option value to save to the corresponding “cocktailID”, in the “value” field, and a “1” posted to the counter field.
-any help is appreciated -matt
Just include the current ID when you send teh form like this
This will then return the ID along with the form results at which time you will have the cocktailID available