Search code examples
phpmysqlsqlhtml-table

Change value from 0 to 1 in database after click on button


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>";

Solution

  • 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.