[PHP] Update Tables using forms.

Status
Not open for further replies.

Livar

Now 35% cooler!
Oct 15, 2010
846
86
Hey thar, I'm trying to update the users table, this is what it'll really do - update users where username is %name% set motto %motto%;

Does someone mind posting a form and the PHP update please. I can't figure it out.

This is my code so far that shows the motto if you've got one, but I need to know how to update the users table using it;

<?php

if (strlen($motto) == 0)
{
$motto = "";
}

echo '';
echo '
<form method="post">
<input type="hidden" name="token" value="SEC-467_0439d6b4d2982cb820664c100db82df61" />
<input type="text" name="motto" value="' . $motto . '" style="margin-right: 5px; width: 175px;" />
<input type="submit" value="Save" name="hidden_motto" style="width: 65px;" />
</form>

';

?>
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,637
2,389
Add a query like this:

PHP:
mysql_query( "UPDATE users SET `motto` = '$motto' WHERE `username` = '$username'" );
 

Mac

New Member
Feb 9, 2011
111
2
PHP:
<?php
/* A simple motto change programmed by Mac for powahcoder */
$actual_motto = mysql_query("SELECT motto FROM users WHERE username='".$_SESSION["username"]."'"); # If your query is not so , then change it!
$new_motto = $_POST["motto"];
if($_POST["submit button name"]): # Change submit button name!
	if($new_motto): 
		mysql_query("UPDATE users SET motto = '".$new_motto."' WHERE username = '".$_SESSION["username"]."'");
		echo "Motto is changed!";
	else:
		mysql_query("UPDATE users SET motto = 'No motto entered' WHERE username='".$_SESSION["username"]."'");
		echo "Your motto is changed to 'No motto entered'";
	endif;
else:
?>
	<form method="post">
<input type="hidden" name="token" value="SEC-467_0439d6b4d2982cb820664c100db82df61" />
<input type="text" name="motto" value="<?php echo $actual_motto; ?>" style="margin-right: 5px; width: 175px;" />
<input type="submit" value="Save" name="hidden_motto" style="width: 65px;" />
</form>

<?php
endif;
?>
 
Status
Not open for further replies.

Users who are viewing this thread

Top