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

单击按钮后,在数据库中将值从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>";

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.

Question is a bit vague but...

Create a listener for your "Do" buttons. Perhaps assign id's to the buttons that match the ID of the database record. Have a section of php that makes an sql update call on the proper table. When the button is clicked, update that records status.

It would be more help if you were to have a more specific question.