Skip to content Skip to sidebar Skip to footer

How To Update Data In An Sql Database

I have already build a functioning login page which redirects the user the index.php file. From previous help, I was able to get the wage and display it on the page depending on w

Solution 1:

I wont give you the code unless you demonstrate as previous commentator said. However I will give you a an overview so you can work at it your self.

update.php

Check if your is logged in.

if TRUE, continue.

get the new wage from the form

$new_wage = $_POST['new_wage'];

Be sure to validate and clean the $new_wage variable.

Next stage assumes your using PDO

$params = array($new_wage, $logged_in_user_id);

$update = "UPDATE user_registration SET wage=? WHERE user_id=?";

$pdo->prepare($update);
$pdo->execute($params);

Solution 2:

First of all if you are using session variables make sure you start the session -session_start();

$username = '$_SESSION['MM_Username'];';

should be

$username = $_SESSION['MM_Username']; (without single quotes)

$wage = $_POST['wage-new'];

should be

$wage = $_POST['new_wage']; as you named it in your html file

you are selecting database user_registation and I assume it should be user_registration

And last, think about switching to PDO or mysqli.

Post a Comment for "How To Update Data In An Sql Database"