嗨,我的表单中包含评分,姓名,电子邮件和评论。我可以插入姓名,电子邮件和评论的用户输入数据。但不知道如何在数据库中存储星级评分。任何人都请帮助我。感谢我如何在mysql数据库中存储星级评分的值
<?php
if(isset($_POST['submit']))
{
$name = $_POST['name'];
$email = $_POST['email'];
$comments = $_POST['comments'];
$ratings = $_POST['ratings'];
$link = mysqli_connect("localhost", "root", "", "imakr");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$res = mysqli_query($link, "insert into imakr.customer_review(name, email, comments, ratings) values('$name','$email','$comments', '$ratings')");
if($res)
{
echo "Your feedback is saved";
}
else
{
echo " OOPs!! there is some error. Please check the fields";
}
}
?>
<form id="customer_review" name="cust_rev"action="" method="post" onsubmit="return validate()">
<table width="535" border="0">
<tr>
<td>Rate This Product:
</td>
<td>
<span id="rateStatus">Rate Me...</span>
<span id="ratingSaved">Rating Saved!</span>
<div id="rateMe" title="Rate Me...">
<a onclick="rateIt(this)" id="_1" title="Poor" onmouseover="rating(this)" onmouseout="off(this)"><span class="ratings">1</span></a>
<a onclick="rateIt(this)" id="_2" title="Not Bad" onmouseover="rating(this)" onmouseout="off(this)"><span class="ratings">2</span></a>
<a onclick="rateIt(this)" id="_3" title="Pretty Good" onmouseover="rating(this)" onmouseout="off(this)"><span class="ratings">3</span></a>
<a onclick="rateIt(this)" id="_4" title="Excellent" onmouseover="rating(this)" onmouseout="off(this)"><span class="ratings">4</span></a>
<a onclick="rateIt(this)" id="_5" title="Marvellous" onmouseover="rating(this)" onmouseout="off(this)"><span class="ratings">5</span></a>
</div>
</td>
</tr>
<tr>
<td width="129"><span class="titles">Name</span><span class="star">*</span>:</td>
<td width="396"><label for="name"></label>
<input type="text" name="name" id="name" /></td>
</tr>
<tr>
<td><span class="titles">Email</span><span class="star">*</span>:</td>
<td><label for="email"></label>
<input type="text" name="email" id="email" /></td>
</tr>
<tr>
<td height="61">Comments:</td>
<td><label for="comments"></label>
<textarea name="comments" id="comments" cols="45" rows="5" onchange="maxlength('comments', 500)"></textarea></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="submit" id="submit" value="Submit" /></td>
</tr>
</table>
<p> </p>
</form>
立即停止使用此代码。它容易受到SQL注入的影响。您正在使用已弃用的API。学习[*准备的语句*](http://j.mp/T9hLWi),并使用[PDO](http://php.net/pdo)或[MySQLi](http://php.net/ mysqli) - [这篇文章](http://j.mp/QEx8IB)将帮助你决定哪个。 – Kermit 2013-03-27 15:29:17
@波兰王子对不起,你能告诉我为什么吗?我是一名初学者。 – 2013-03-27 15:30:46
是的,我会推荐使用mysqli,看看这个链接http://php.net/manual/de/book.mysqli.php – makim 2013-03-27 15:31:45