HELP WITH PHP AND MYSQL

Status
Not open for further replies.

bodge

ayy lmao
Oct 31, 2011
406
54
Hey Devbest, I need help with adding a PHP form that edits the MySQL table.
I want it to edit the "status column" the closest I can get is when I type something in and hit okay it makes a whole new user... :L

Can you help?

PHP:
<?php
$status = $_POST ['status'];
mysql_query("INSERT INTO users (status) VALUES ('$status')");
?>

HTML:
<form action="<?php $_SERVER['PHP_SELF']?>" method="post" class="status">
<input type="text" name="status" size="32" placeholder="Status"><span required>*</span>
<input type="submit" value="Okay" />

status = VARCHAR(32)
 

Kaz

BooYah
Staff member
Nov 16, 2010
3,064
1,025
Then why are you 'inserting' ?? that makes no sense.

You will do:
PHP:
<?php
$status = $_POST ['status'];
mysql_query("UPDATE users SET status = '".$status.'" ");
?>
After $status, you could maybe have WHERE username = $user (with $user getting the logged in user
 

Heaplink

Developer & Designer
Nov 9, 2011
510
173
PHP:
mysql_query("UPDATE users SET status = '{$status}' WHERE id = {$userid}");

Note that $userid is the ID of the user (obviously) so find the right variable.

Also, use PDO or MySQLi, both for security and for later support (Old mysql functions will be deprecated)
 

bodge

ayy lmao
Oct 31, 2011
406
54
Then why are you 'inserting' ?? that makes no sense.

You will do:
PHP:
<?php
$status = $_POST ['status'];
mysql_query("UPDATE users SET status = '".$status.'" ");
?>
After $status, you could maybe have WHERE username = $user (with $user getting the logged in user

Worked perfectly thanks! :D
 
Status
Not open for further replies.

Users who are viewing this thread

Top