【发布时间】:2012-05-02 00:10:11
【问题描述】:
我正在尝试通过让用户提交表单来更新 mysql 数据。
用户可以更新比赛结果,获胜队在mysql中获得+1胜利。用户可以随时查看游戏表格并更新/更改游戏。
我的问题是,当用户再次更新表单时,如何防止现有获胜团队第二次或第三次 +1 获胜。
例如:A 队击败 B 队,用户提交表单。 mysql会为A队+1获胜列。后来用户发现C队击败D队并再次提交表格,但A队,B队,C队和D队都是同一个表格,所以如果用户再次提交表格,A队将在获胜栏中获得2胜,C队将获得1胜。我只想让 A 队只赢 1 场。不确定是否可能。感谢您的回复。
表单HTML
<form>
//First time The user only select the winning team in winner1 and submit the form
//Second time the user see the page, The Team A will be selected base on 1 win in mysql
//when user tried to submit again,
//Team A will get another 1 win in its record which is not true.
<select name='winner1'>
<option>Select the winner</option>
<option>Team A</option>
<option>Team B</option>
</select>
//User didn't select the winning team first time
//User submits again with the selected winner team for winner2 .
//database will be Team A => 2 wins, Team C =>1 win.
<select name='winner2'>
<option>Select the winner</option>
<option>Team C</option>
<option>Team D</option>
</select>
</form>
我的结果 php
for ($i=1; $i<3; $i++){
$winner=$_POST['winner'.$i]
//omit some php query code.......
select win from team where teamName ='$winner'
//get win and +1 to win
$win++
update team set win='$win' where teamName ='$winner'
}
我希望我能清楚地解释我的问题。感谢您的回复。
【问题讨论】:
标签: php mysql sql sql-update