douji9518 2017-12-29 17:50
浏览 123
已采纳

单击按钮后,在数据库中将值从0更改为1 [关闭]

I have a table:

enter image description here

I want to change "pending" to "payed" when i will click on button "Do" In the database if value of column "status" is 0 , then write pending, and if value is 1 - payed.

Code of table:

$host="localhost"; 
$user="***";
$pass="***"; //установленный вами пароль
$db_name="u0304752_sam";
$link=mysql_connect($host,$user,$pass);
mysql_select_db($db_name,$link);

$result=mysql_query("SELECT id,payeer,summa,dates_add, status FROM pays_tnmleafeuj  ORDER BY id DESC"); 

//$result - ассоциированный массив, т.е. таблички, у которой есть названия столбцов 

echo "<table border=1 width=700px>";
echo "<tr><th>ID</th><th>Кошелёк</th><th>Сумма</th><th>Дата</th><th>Статус</th><th>-</th></tr>";
while ($row=mysql_fetch_array($result )){
$id=$row[0];
$payeer=$row[1];
$summa=$row[2];
$data=$row[3];
$status=$row[status];
if($status == 0){
$status = 'pending';
} elseif($status == 1){
$status = 'payed';
} 

echo "<tr><td class=id>$id</td><td>$payeer</td><td>$summa</td><td>".date('Y-m-d H:i', $row[dates_add])."</td><td>$status</td><td><input type=button value=Do SQL></td></tr>";
}
echo "</table>";
  • 写回答

2条回答 默认 最新

  • douzuo0711 2017-12-29 18:09
    关注

    Checkout this answer

    Clicking a button is client side whereas updating database is Server side. So use an ajax call as described in above answer to call some php function which will then update the database.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?