我正在为我的系统做这个单选按钮(如星级)。我已经尝试了一切,但我的数据没有插入我的数据库。当我运行时并没有说我有错误但是当我提交我的按钮时它只显示“更新数据时出错”
这是我的单选按钮代码
<legend>Star Rating</legend><br>
<center>
<form action="ratingprocess.php" method="post">
Contractor Name: <select name="username"><br>
<option selected>Select Contractor</option>
<?php
$con=mysqli_connect("localhost","root","","fyp");
if (mysqli_connect_errno())
{echo "Failed to connect to MySQL: " . mysqli_connect_error();}
$sql="SELECT * FROM contractor";
$result = mysqli_query($con, $sql);
while($row = mysqli_fetch_array($result))
{
echo '<option value='.$row['username'].'>'.$row['username'].'</option>';
}
?>
</select><br>
<br><br>
<div class="star">
<input type="radio" name="star" class="star-1" id="star-1" value="1" />
<label class="star-1" for="star-1">1</label>
<input type="radio" name="star" class="star-2" id="star-2" value="2" />
<label class="star-2" for="star-2">2</label>
<input type="radio" name="star" class="star-3" id="star-3" value="3" />
<label class="star-3" for="star-3">3</label>
<input type="radio" name="star" class="star-4" id="star-4" value="4" />
<label class="star-4" for="star-4">4</label>
<input type="radio" name="star" class="star-5" id="star-5" value="5" />
<label class="star-5" for="star-5">5</label>
</div>
<br>
<input type = "submit" value = "Submit"> <t> </t>
</center>
</div>
</fieldset>
</form>
这是我的PHP代码
<?php
include("connection.php");
$con = mysqli_connect("localhost","root","","fyp");
$username=$_POST["username"];
$rate=$_POST["star"];
if (!$con)
{
die("Cannot execute sql.");
}
$update_sql="UPDATE contractor SET star='$rate' WHERE username = '$username'";
$sql_result=mysqli_query($con,$update_sql);
if (!$sql_result)
{
die ("Error in updating the data");
}
else
echo "Succesfully send the rating.";
?>