-3

我已经发布了这个问题 2 次都没有工作我重新编写了脚本,现在我遇到了更多问题

这是我在第一页上的代码:

<?php

$host="XXXX"; // Host name 
$username="XXXX"; // Mysql username 
$password="XXXX"; // Mysql password 
$db_name="XXXX"; // Database name 
$tbl_name="XXXX"; // 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'>Post #</th><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='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['id']; ?> </b></i></td>
<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><a href='works.php?id=<? echo $rows['id']; ?>'><img src='images/ThumbsUp.png' height='30' width='30'>  </a>&nbsp;&nbsp;&nbsp;<a href='dworks.php?id=<? echo $rows['id']; ?>'><img   src='images/ThumbsDown.png' height='30' width='30'></a>

</td> 
</tr>

<?php
// close while loop 
}
?>

<?php
// close connection; 
mysql_close();
?>

</table>

我不确定这个页面是否是问题的一部分......

这是第二页

<?php
$host="XXXX"; // Host name 
$username="XXXX"; // Mysql username 
$password="XXXX"; // Mysql password 
$db_name="XXXX"; // Database name 
$tbl_name="XXXX"; // 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");

// get value of id that sent from address bar
$id=$_GET['id'];

// Retrieve data from database 
$sql="SELECT * FROM $tbl_name WHERE id='$id'";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);
?>


<?php
$host="XXXX"; // Host name 
$username="XXXX"; // Mysql username 
$password="XXXX"; // Mysql password 
$db_name="XXXX"; // Database name 
$tbl_name="XXXX"; // 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");

// update data in mysql database 
$sql="UPDATE `$host`.`$username` 
SET `works` = `works` + 1 WHERE `$db_name`.`id` = '".$id."'";
$result=mysql_query($sql);

// if successfully updated. 
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='list_records.php'>View result</a>";
}

else {
echo "ERROR";
}

?>

我在我的自定义错误页面上收到错误,我不知道为什么.. 我试图让它添加 +1 到我的表上名为 works 的列默认值为 0,我无法添加它+1 表示值为 1,有人单击图像链接,值变为 2,再单击变为 3,依此类推

是的,这是真正的 mysql 登录信息,这不是我的烫发网站,它只是为了测试我的代码以放在我的真实网站上,所以我不在乎分享

4

2 回答 2

1

更改以下

mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

$link=mysql_connect($host, $username, $password); 
if (!$link) {
    die('Not connected : ' . mysql_error());
}
$db_selected=mysql_select_db("$db_name", $link);
if (!$db_selected) {
    die('Not selected : ' . mysql_error());
}

获取数据并打印

$sql="SELECT * FROM $tbl_name WHERE id='$id'";
$result=mysql_query($sql);
if(mysql_num_rows($result))
{
    while($row = $result->fetch_assoc()) {
        echo 'id: '. $row['id'].'<br />'; // replace with real field name
        echo 'name: '. $row['name']'<br />'; // replace with real field name
    }
 }
于 2012-12-27T08:37:10.793 回答
-1

将最后一个查询更改为 $sql="UPDATE tylted SET works = works + 1 WHERE id = $id;"; $result=mysql_query($sql); 它的工作原理我谷歌搜索了 9 或 10 分钟,发现 MySQL 更新列 +1?我也在这里搜索过,但它没有用感谢人们像你一样提供帮助

于 2012-12-27T09:26:55.820 回答