通过创建简单的Php,MySql投票系统来更新问题 [英] Update Problems With Creating Simple Php,MySql Voting System

查看:45
本文介绍了通过创建简单的Php,MySql投票系统来更新问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我所做的是制作一个脚本来显示数据库,并且我启动了一个投票系统,该系统应该更新作品,如果有人单击作品,则在mysql数据库中的dworks会将作品的价值从3变为4和4变为5如果在dworks部分中再次单击相同的按钮,但它没有更新数据库,请帮助我

ok so what i have done is made a script to show database and i inclided a voting system that SHOULD update the works,dworks in mysql database if someone clicks works it changes the value of works from say 3 to 4 and 4 to 5 if clicked once more same thing for the dworks part but it dosent update the database please help me

<?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>

推荐答案

UPDATE语句不能那样工作,如果要增加列的值,应该像这样.

the UPDATE statement doesn't work like that, it should be like this if you want to increment the value of the column.

UPDATE `Db`.`Users` 
SET `works` = `works` + 1 
WHERE `tylted`.`id` = $id 
// LIMIT $id

这篇关于通过创建简单的Php,MySql投票系统来更新问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆