dimanche 22 mars 2015

How to make a form that updates a database?

I need to update a database (basically just perform some simple queries) when a user fills in some values in my form. I need the submit button to do multiple queries like: UPDATE table SET column1 = column1 - $_POST['bananas'] WHERE id = $steamID UPDATE table SET column1 = column1 + $_POST['bananas'] WHERE id = $_POST['steamid']


I am using this to post the information that will be used to update the database



<form action="bananas.php" method="POST">
Amount:<br>
<input type="text" name="bananas"><br>
Recipient SteamID:<br>
<input type="text" name="steamid"><br>
<input type="submit" name="bananas|steamid"><br>
<?php
if (isset($_POST['submit']))
{
// Execute this code if the submit button is pressed.
$formvalue = $_POST['bananas'];
$formvalue = $_POST['steamid'];
}
echo $_POST['bananas'];
echo $_POST['steamid'];
?>


I can't have the queries active on the page giving errors because the values aren't filled in. They must only do the query and update my database when the user presses submit. How can I use this form to execute the queries I need when the user presses submit?


Things to note: $steamID is already the variable of the id of the user that is logged in and I already have the connection to my database and all of that setup. The form is all I need help with. Thank you, all help is greatly appreciated! :)


Aucun commentaire:

Enregistrer un commentaire