I have created a webpage that gets the user to login, if they havent got an account then they can register and is creates a new user for them.
This is the table users in the database (user_registration)
user_id username password email wage
1 johnsmith jsmith99 jsmith@gmail.com 0
2 davidscott dscott95 davidscott@gmail.com 0
When a new user registered, the default value for the wage is 0. I want them to be able to edit this through the use of a form - this is the HTML code for the form:-
<form method="post" action="<?php $_PHP_SELF ?>">
<input name="new-wage" type="text" id="new-wage" class="textbox" placeholder="New Wage">
<input name="update" type="submit" id="update" value="Update" class="btn">
</form>
PHP Code: (note- the php and the html form are all in the same file(index.php) )
<?php
if(isset($_POST['update']))
{
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
$user_id = $_SESSION['MM_Username'];;
$wage = $_POST['new-wage'];
$query = "UPDATE users ".
"SET wage = '$wage' ".
"WHERE user_id = '$user_id'" ;
mysql_select_db('user_registration');
$retval = mysql_query( $query, $conn );
if(! $retval )
{
die('Could not update data: ' . mysql_error());
}
echo "Updated data successfully\n";
mysql_close($conn);
}
else
{
?>
When i fill in this form and hit the update button, it reloads the webpage and displays Updated data successfully which is exactly what should happen. BUT - when I refresh the table in PHP My Admin, it keeps the wage as 0, and not what i entered in the form.
Has anyone got any ideas what might be wrong with my code?
Thanks in advance for any answers.
PS.- I know that I have used the functions mysql_* and not mysqli_, simply because i dont know how to convert it, can you also help me with this??