UPDATE of database information

Asked

Viewed 40 times

0

I have a table, where there is a field called (PAY), the default value of it is "PAY".

Banco de Dados

I made the following code, to change the VALUE "PAY" to "PAID"

$results = "UPDATE snaps SET Pagamento='PAGO' WHERE id= 27";

However, it only works, for 1(one) user ID, I wanted to know how to improve this code, for when I run it, it ask the user code(id) instead of having an ID already pre-defined in the case the "27".

Thanks to all who help.

1 answer

1


$id_form from a form, can be method Post or GET

Example of Post method:

<form method="post" action="PAGINA_DESTINO">
   <input type="number" name="id"><br>
   <input type="submit" value="enviar">
</form> 

PAGINA_DESTINO

$id_form = mysql_real_escape_string($_POST['id']);

$query = mysql_query("SELECT * snaps where id= '$id_form'");

while($row = mysql_fetch_array($query))
{
    $id= $row['id'];
}

//O update  
$results = "UPDATE snaps SET Pagamento='PAGO' WHERE id= '$id'";

NOTE: Use mysqli or PDO Mysql Deprecated

Browser other questions tagged

You are not signed in. Login or sign up in order to post.