Reputation: 17
I have a form in the previous page which allows users to fill in the details that they wish to edit which will be posted to another page.
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$query = "UPDATE member SET first_name ='$first_name' WHERE member_id= '".$_SESSION['member_id']."'";
$query = "UPDATE member SET last_name ='$last_name' WHERE member_id= '".$_SESSION['member_id']."'";
// execute SQL statement
$status = mysqli_query($link,$query) or die(mysqli_error($link));
Apparantly, only the last query works. If the user edits the $first_name, the chang
Upvotes: 0
Views: 88
Reputation: 6152
Well, this is a basic Programming thing.
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$query1 = "UPDATE member SET first_name ='$first_name' WHERE member_id= '".$_SESSION['member_id']."'";
$query2 = "UPDATE member SET last_name ='$last_name' WHERE member_id= '".$_SESSION['member_id']."'";
// execute SQL statement
$status1 = mysqli_query($link,$query1) or die(mysqli_error($link));
$status2 = mysqli_query($link,$query2) or die(mysqli_error($link));
Upvotes: 1
Reputation: 4197
You are changing the content of $query
several times before executing. Apperently your $query
contains the value that you last assignet to it.
This is the query that is then getting executed.
Upvotes: 0
Reputation: 6573
you only execute one query and as you overwrite $query with the second declaration you'll only execute the last...
you can update both in query like so:
$query = "UPDATE member SET first_name ='$first_name' ,last_name ='$last_name' WHERE member_id= '".$_SESSION['member_id']."'";
Upvotes: 1
Reputation: 614
try combining query $query = "UPDATE member SET first_name ='$first_name',last_name ='$last_name' WHERE member_id= '".$_SESSION['member_id']."'";
Upvotes: 0