输入值无法保存到数据库中

时间:2016-03-13 07:08:42

标签: javascript php

这是我的两个php文件,我正在尝试多星评级系统。下面的代码仅适用于一个类别。问题是用户可以单击星号,但保存到数据库中的值为0.实际输入值无法读取或保存到数据库中。是否需要使用点击功能或任何其他方式来解决此问题。谢谢。

这是我的ratings.php

<html>
<body>
<?php
$conn = mysqli_connect('localhost', 'root', '', 'pse2');

if (mysqli_connect_errno()) {
    echo "<p>Connection Error</p>" 
    . "<p>" . mysqli_connect_error() . "</p>\n";
    die;
}

?>

<form method="post" action="insert_rating.php">
<div class="div">
  <p>Environment</p>
  <input type="hidden" id="environment1_hidden" value="1">
  <img src="star1.png" onmouseover="change(this.id);" id="environment1" class="environment">
  <input type="hidden" id="environment2_hidden" value="2">
  <img src="star1.png" onmouseover="change(this.id);" id="environment2" class="environment">
  <input type="hidden" id="environment3_hidden" value="3">
  <img src="star1.png" onmouseover="change(this.id);" id="environment3" class="environment">
  <input type="hidden" id="environment4_hidden" value="4">
  <img src="star1.png" onmouseover="change(this.id);" id="environment4" class="environment">
  <input type="hidden" id="environment5_hidden" value="5">
  <img src="star1.png" onmouseover="change(this.id);" id="environment5" class="environment">
</div>

<input type="hidden" name="environmentrating" id="environmentrating" value="0">
<input type="submit" value="Submit" name="submit_rating">
</form>
</body>
</html>

这是我的insert_rating.php

if(isset($_POST['submit_rating']))
{
$conn = mysqli_connect('localhost', 'root', '', 'pse2');


if (mysqli_connect_errno()) {
    echo "<p>Connection Error</p>" 
    . "<p>" . mysqli_connect_error() . "</p>\n";
    die;
 }

 $environment=$_POST['environmentrating'];

 $insertRating = "insert into rating (environment) values('$environment')";

 $success = mysqli_query($conn, $insertRating);

 $conn->close();
 }

0 个答案:

没有答案