好的,所以我所做的是制作了一个脚本来显示数据库并包含一个应该更新作品的投票系统,dworks
如果有人点击作品,它会在 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="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% WORKS 和 2% DOSENT WORK 如果点击按钮 WORKS,它将变为 5 到 6 并再次点击 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}
等等等等你有点明白吗?我明白他想做什么,但我不知道该怎么做?