0

好的,所以我所做的是制作了一个显示数据库的脚本,并且我加入了一个应该更新作品的投票系统,如果有人点击作品,它会在 mysql 数据库中将作品的值从 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>
4

1 回答 1

1

UPDATE语句不是这样工作的,如果你想增加列的值,它应该是这样的。

UPDATE `Db`.`Users` 
SET `works` = `works` + 1 
WHERE `tylted`.`id` = $id 
// LIMIT $id
于 2012-12-27T03:55:07.570 回答