我有一个显示 mysql 条目数据的页面,具体取决于用户单击的链接($pagename)。我想知道如何创建一个非常基本的评级系统,它将由一个下拉选项为 1 的表单组成到5,当用户提交这个值时,它会将数据发布到当前页面上条目的相应ID。
<?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>"
?>
我想将评分保存到的表通过“cocktailID”链接到上面代码中正在回显的数据。
而“tblRating”的表结构是:ratingID、cocktailID、value、counter..
因此,我希望将选项值保存到“value”字段中相应的“cocktailID”,并将“1”张贴到 counter 字段。
- 任何帮助表示赞赏 -matt