我有一个html表单,我使用下拉列表或选项显示所有候选列表。选项的所有数据都来自数据库。这里:
<form method ="post" action="">
<div class="gov-align">
<div class="hero-body-candidate_gov">
<font color="black">Candidate for Governor</font>
</div>
<div class="governor">
<div class="gov-margin">
<?php
$governor= "SELECT a.cand_id, cand_Lname, cand_Fname, cand_partylist,cand_position, image FROM cand_info as a INNER JOIN cand_account as b ON a.cand_id=b.cand_id INNER JOIN cand_position as c ON b.cand_id=c.cand_id WHERE cand_position = 'President'";
$res = mysqli_query($con,$governor);
while($row=mysqli_fetch_array($res)){ $governor_id=$row['cand_id']; ?>
<img class="gov" src="<?php echo $row['image'];?>" width="150" height="150" border="0" onmouseover="showtrail('<?php echo $row['image'];?>','<?php echo $row['cand_Fname']." ".$row['cand_Lname'];?> ',200,5)" onmouseout="hidetrail()">
<?php
}
?>
</div>
</div>
<div class="select_gov">
<div class="margin-gov">
<select name="governor" class="span222">
<option class="option">--Select Candidate--</option>
<?php
$governor= "SELECT a.cand_id, cand_Lname, cand_Fname, cand_partylist,cand_position FROM cand_info as a INNER JOIN cand_account as b ON a.cand_id=b.cand_id INNER JOIN cand_position as c ON b.cand_id=c.cand_id WHERE cand_position = 'President'";
$res = mysqli_query($con,$governor);
while($row=mysqli_fetch_array($res)){ $governor_id=$row['cand_id']; ?>
<option name="" value="<?php echo $row['cand_id'] ?>" class="option"><?php echo $row['cand_Fname']." ".$row['cand_Lname']; ?></option>
<?php } ?>
</select>
</div>
</div>
</div>
<div class="thumbnail_widget">
<div class="submit-vote">
<button id="submit" id="vote" class="btn btn-success" name="submit"><i class="icon-thumbs-up icon-large"></i> Submit Vote</button>
</div>
</div>
这是html下面的php行。
<?php
if(isset($_POST['submit'])) {
$gov = isset($_['cand_id']) ? $_POST['cand_id'] : '';
$sql1="UPDATE cand_votecount SET votecount = votecount + 1 WHERE cand_id = '$gov'";
$result1 = mysqli_query($con,$sql);
}
?>
</form>
我想为学生选择的候选人的投票数添加一个。每当我点击提交时,它只刷新,没有任何反应。
PS。我知道我的代码可以很容易地注入sql注入。无需对此发表评论。
答案 0 :(得分:0)
做一个小改动
if(isset($_POST['governor']))
{
$sql1="UPDATE cand_votecount SET votecount = votecount + 1 WHERE cand_id =".$_POST['governor'];
$result1 = mysqli_query($con,$sql);
}