gpt4 book ai didi

php - MySql 更新上的投票系统将不起作用

转载 作者:太空宇宙 更新时间:2023-11-03 11:03:19 27 4
gpt4 key购买 nike

<分区>

好的,所以我所做的是制作一个脚本来显示数据库,并包括一个应该更新作品的投票系统,mysql 数据库中的 dworks 如果有人点击作品,它会改变作品的值(value) say 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>&nbsp; <? 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”,所以说按钮 WORKS 上的投票是 5% WORKS 和 2% DOSENT WORK 如果它被点击它会改变 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}

等等等等你有点明白了吗?我明白他想做什么,但我不确定该怎么做?

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com