UPDATE of database information

0

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

Imadethefollowingcodetochangethe"PAY" VALUE to "PAYMENT"

$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, so when I run it, it asks for the user ID (id), instead of having an ID already pre-defined in the case the "27".

Thanks to all who help.

    
asked by anonymous 15.06.2017 / 22:57

1 answer

1

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

Post method example:

<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

    
16.06.2017 / 00:04