[PHP] Updating Tables using forms.

Status
Not open for further replies.
You shouldn't ask for complete scripts here (read the rules) but I'll give you a guideline. What you're looking for is like this:

file.php
PHP:
<?php
//mysql connection here
if($_POST["go"])
{
$motto = $_POST["motto"];
$username = $_POST["username"]; //as I say in the HTML bit, if you have this as a session variable, use that
//you'll have to sanitize these variables of course
$sql = "UPDATE `table_name` SET `motto` = '". $motto ."' WHERE `username` = '". $username ."'";
?>
}

html bit:
Code:
<form method="post" action="file.php">
Username: <input type="text" name="username" /> <!-- Or if you have this in a session variable leave this out -->
Motto: <input type="text" name="motto" />
<input type="submit" name="go" value="Change motto" />
</form>

Sorry for the sucky standards, doing this plain text.
 
You shouldn't ask for complete scripts here (read the rules) but I'll give you a guideline. What you're looking for is like this:

file.php
PHP:
<?php
//mysql connection here
if($_POST["go"])
{
$motto = $_POST["motto"];
$username = $_POST["username"]; //as I say in the HTML bit, if you have this as a session variable, use that
//you'll have to sanitize these variables of course
$sql = "UPDATE `table_name` SET `motto` = '". $motto ."' WHERE `username` = '". $username ."'";
?>
}

html bit:
Code:
<form method="post" action="file.php">
Username: <input type="text" name="username" /> <!-- Or if you have this in a session variable leave this out -->
Motto: <input type="text" name="motto" />
<input type="submit" name="go" value="Change motto" />
</form>

Sorry for the sucky standards, doing this plain text.
You've not even executed the sql query, that won't work
 
Status
Not open for further replies.
Back