php - 我如何在mysql数据库中存储星级评分的值

标签 php html mysql css

<分区>

您好,我有一个包含评级、姓名、电子邮件和评论的表格。我能够插入姓名、电子邮件和评论的用户输入数据。但不知道如何将星级评分存储在数据库中。任何人都请帮助我。谢谢

      <?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>&nbsp;</td>
      <td><input type="submit" name="submit" id="submit" value="Submit" /></td>
    </tr>
  </table>
  <p>&nbsp;</p>
</form>

最佳答案

  1. 选择一种数据类型,如果您打算只存储整数评分,[例如:3/5 星],则使用 TINYINT。如果您要存储星星的分数,[例如:3.5/5 颗星],则使用 DECIMAL(2,1)
  2. 存储一些关于用户的识别信息以防止多重评级。如果用户不需要登录即可对某些内容进行评分,则将其 IP 地址与评分一起存储。

关于php - 我如何在mysql数据库中存储星级评分的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15662722/

相关文章:

php - 保持两个 mySQL 数据库(在不同位置)同步的策略?

php - 休息 Api 模式解释?

php - GroupBy Laravel MySql 查询

javascript - 使用 Javascript 突出显示范围不起作用

html - 框上的跨浏览器阴影

html - <q>标签和html中手动添加双引号一样吗?

php - 我如何急切加载最新记录,其中每条记录都具有特定列的不同值?

php - 我的 sql 查询在 json 响应中返回 3 行相同的数据类型

php - 多行的 SQL 语法

从 phpmyadmin 导出时 MySql GROUP_CONCAT 失败