嗨,我的表單中包含評分,姓名,電子郵件和評論。我可以插入姓名,電子郵件和評論的用戶輸入數據。但不知道如何在數據庫中存儲星級評分。任何人都請幫助我。感謝我如何在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