如何使用提交按钮根据id更新数据库的元素
问题描述:
I have this code that inserts data into a table at index, but how can I make the submit button modifystatus work? I have been trying with no results, the aim is that when I press the submit button "atendido" the table of the database column name status will be = 0, depending the on id that is updating
<?php if($total>0 && $search!='')
{
do {
echo "<tr><form method='post' action='../solicitudes/modifystatusdown.php'>
<td style='width:20%; '><input type='hidden' name='$fila[nombre]''><input type='text'>";
echo $fila['nombre'];
echo "</td><td style='width:20%;'>";
echo $fila['telefono'];
echo "</td><td style='width:20%;'>";
echo "<input type='Submit' name='delete' value='Atendido'></td></form></tr>";
}
while ($fila=mysqli_fetch_assoc($resultado));
} ?>
this is the modifystatus.php
<?php
$nombre = $_POST[$nombre];
$nombre = $_GET['nombre'];
$link = mysql_connect("localhost","root","");
if($link)
{
mysql_select_db("users",$link);
}
mysql_query("UPDATE usuarios SET status=0 WHERE nombre = '$nombre'");
?>
答
You don't give your complete logic, but it is more likely that you want to use a specific name for your input and change the value. For example:
<?php $nombre = $fila['nombre'] ?>
<td style='width:20%; '>
<input type='hidden' name='nombre' value='$nombre']'><input type='text'>";
Then the value
$nombre = $_POST['nombre']
will contain the name.
答
So why do you use:
$nombre = $_POST[$nombre];
$nombre = $_GET['nombre'];
you just need:
$nombre = $_POST[$nombre];
and stop using mysql_
it is deprecated, use mysqli or PDO