好的,我所做的是创建一个脚本来显示数据库并包含一个投票系统,该系统应该更新工程,如果有人点击工作,则在mysql数据库中dworks
它会改变作品的值从3到4如果dworks
部分再次点击了同样的东西,那么4到5,但它不会更新数据库,请帮助我:
以下是我的代码:
<?php require "manybr.htm" ?>
<style>
body
{
background-image:url('images/bg.png');
}
</style>
<?php
$host="Host"; // Host name
$username="Username"; // Mysql username
$password="password"; // Mysql password
$db_name="Database Name"; // Database name
$tbl_name="tylted"; // 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);
?>
<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>
<?php
$host="host"; // Host name
$username="Username"; // Mysql username
$password="password"; // Mysql password
$db_name="Database Name"; // Database name
$tbl_name="tylted"; // Table name
if ( isset( $_POST['works'] ) )
{
// query YES +1
//UPDATE tylted SET works = works + 1
$sql="UPDATE `Database Name`.`Username`
SET `works` = `works` + 1
WHERE `tylted`.`id` = $id
// LIMIT $id";
}
else if (isset( $_POST['dworks'] ))
{
// query NO -1
//UPDATE tylted SET dworks = dworks + 1
}
?>
<form method='POST'>
<input type='submit' value='works' name='works'>
<input type='submit' value='dworks' name='dworks'>
</form>
<form method='POST'>
<input type='submit' value='works' name='works'>
<input type='submit' value='no works' name='dworks'>
</form>
</td>
</tr>
<?php
// close while loop
}
?>
</table>
<?php
// close connection;
mysql_close();
?>
<center>
我试图获得
<?php
$host="host"; // Host name
$username="Username"; // Mysql username
$password="password"; // Mysql password
$db_name="Database Name"; // Database name
$tbl_name="tylted"; // Table name
if ( isset( $_POST['works'] ) )
{
// query YES +1
//UPDATE tylted SET works = works + 1
$sql="UPDATE `Database Name`.`Username`
SET `works` = `works` + 1
WHERE `tylted`.`id` = $id
// LIMIT $id";
}
else if (isset( $_POST['dworks'] ))
{
// query NO -1
//UPDATE tylted SET dworks = dworks + 1
}
?>
<form method='POST'>
<input type='submit' value='works' name='works'>
<input type='submit' value='dworks' name='dworks'>
</form>
部分工作就像投票调查一样,每次点击WORKS按钮都会更新数据库'tylted',所以如果单击它更改5到6并单击一次,则按钮WORKS上的投票为5%WORKS和2%DOSENT WORK更多6到7和另一个按钮相同。
说出来就是这样:
Does It Work? | VOTE
9% Yes 2% No | {WORKS} {DOSENT WORK}
单击{WORKS}时将其更改为
Does It Work? | VOTE
10% Yes 2% No | {WORKS} {DOSENT WORK}
当点击{DOSENT WORK}时,它会变为
Does It Work? | VOTE
10% Yes 3% No | {WORKS} [DOSENT WORK}
等等等你有点明白吗?我明白他想做什么,但我不知道该怎么做?
答案 0 :(得分:4)
$sql="UPDATE ..... `works` = `works` + 1 WHERE `tylted`.`id` = id // LIMIT $id";
here is problem--------------------------^^
要么不在查询中,要么
$sql="UPDATE ..... `works` = `works` + 1 WHERE `tylted`.`id` = '".$id."'";
或
$sql="UPDATE ..... `works` = `works` + 1 WHERE `tylted`.`id` = '".$id"' LIMIT '".$id."'";
注意
ext/mysql
PHP扩展程序(提供名为mysql_的所有函数)为officially deprecated as of PHP v5.5.0,将来会被删除。因此,请使用PDO
或MySQLi
好读