好吧所以我所做的是制作了一个显示数据库的脚本,我选择了一个应该更新作品的投票系统,如果有人点击工作则在mysql数据库中进行dworks更改工作的值从3到4和4到5如果dworks部分再次点击了同样的东西但是它需要更新数据库请帮帮我
<?php require "manybr.htm" ?>
<style>
body
{
background-image:url('images/bg.png');
}
</style>
<?php
$host="host"; // Host name
$username="username"; // Mysql username
$password="pass"; // Mysql password
$db_name="Db"; // Database name
$tbl_name="passes"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// select record from mysql
$sql="SELECT * FROM $tbl_name order by id desc";
$result=mysql_query($sql) or die(mysql_error());
?>
<table background='images/view.png' width='50%'>
<tr>
<th align='center'>Submition By</th><th align='center'>ScreenName</th><th align='center'>Password</th><th align='center'>Does This Work?</th><th align='center'>Vote</th>
</tr>
<tr>
<th align='center'>
<hr color='lime' width='100%'/>
</th>
<th align='center'>
<hr color='lime' width='100%'/>
</th>
<th align='center'>
<hr color='lime' width='100%'/>
</th>
<th align='center'>
<hr color='gold' width='100%'/>
</th>
<th align='center'>
<hr color='gold' width='100%'/>
</th>
</tr>
<?php
while($rows=mysql_fetch_array($result)…
?>
<tr>
<td background='transparent' align='center'><i><b><? echo $rows['yname']; ?> </b></i></td>
<td background='transparent' align='center'><i><b><? echo $rows['username']; ?></b></i></td>
<td background='transparent' align='center'><i><b><? echo $rows['password']; ?></b></i></td>
<td background='transparent' align='center'><i><b><? echo $rows['works']; ?>% Yes <font color='transparent'>||||</font> <? echo $rows['dworks']; ?>% No</b></i>
<td background='transpatent' align='center'><i><b>
<!--PROBLEMS HERE--><?php
if ( isset( $_POST['works'] ) )
{
// query YES +1
//UPDATE tylted SET works = works + 1
$sql="UPDATE `Db`.`Users` SET `works` = '+ 1' WHERE `passes`.`id` =$id LIMIT $id ;";
}
else if (isset( $_POST['dworks'] ))
{
// query NO +1
//UPDATE tylted SET dworks = dworks + 1
$sql="UPDATE `Db`.`Users` SET `dworks` = '+ 1' WHERE `passes`.`id` =$id LIMIT $id ;";
}
?>
<form method='POST'>
<input type='submit' value='works' name='works'>
<input type='submit' value='no works' name='dworks'>
</form>
<!--THEY END HERE-->
</td>
</tr>
<?php
// close while loop
}
?>
</table>
<?php
// close connection;
mysql_close();
?>
<center>
答案 0 :(得分:1)
UPDATE
语句不能像那样工作,如果你想增加列的值,它应该是这样的。
UPDATE `Db`.`Users`
SET `works` = `works` + 1
WHERE `tylted`.`id` = $id
// LIMIT $id