Reputation: 31
I am trying to get information to update in my table. I have spent hours and keep going in circles. I think the problem is in my query section toward the end of the code. Any help would be appreciated. Thanks.
<?php require "connect.php"; ?>
<?php
session_start();
if(isset($_SESSION["ID"])){
}else{
header('Location:login.php');
}
?>
<?php
$User = $_SESSION["ID"];
$result = $con->query("select * from BD where ID='$User'");
$row = $result->fetch_array(MYSQLI_BOTH);
$_SESSION["FirstName"] = $row['FirstName'];
$_SESSION["LastName"] = $row['LastName'];
$_SESSION["Email"] = $row['Email'];
$_SESSION["UserName"] = $row['UserName'];
$_SESSION["Password"] = $row['Password'];
?>
<?php
if(isset($_Post['Update'])){
$UpdateFName = $_Post['FirstName'];
$UpdateLName = $_Post['LastName'];
$UpdateEmail = $_Post['Email'];
$UpdateUName = $_Post['UserName'];
$UpdatePassword = $_Post['Password'];
$sql = $con->query("UPDATE BD SET FirstName = '{$UpdateFName}', LastName = '{$UpdateLName}', Email = '{$UpdateEmail}', UserName = '{$UpdateUName}', Password = '{$UpdatePassword}' where ID= $User");
header('Location: update.php');
}
?>
Upvotes: 0
Views: 85
Reputation: 7
<?php
if (isset($_POST['Update'])) {
$UpdateFName = isset($_POST['FirstName']) ? $_POST['FirstName'] : '';
$UpdateLName = isset($_POST['LastName']) ? $_POST['LastName'] : '';
$UpdateEmail = isset($_POST['Email']) ? $_POST['Email'] : '';
$UpdateUName = isset($_POST['UserName']) ? $_POST['UserName'] : '';
$UpdatePassword = isset($_POST['Password']) ? $_POST['Password'] : '';
$sql = $con->query("UPDATE BD SET
`FirstName` = '$UpdateFName',
`LastName` = '$UpdateLName',
`Email` = '$UpdateEmail',
`UserName` = '$UpdateUName',
`Password` = '$UpdatePassword'
WHERE
`ID` = $User"
);
header('Location: update.php');
}
Upvotes: 1
Reputation: 1181
You have used the post method wrongly. You should use post method like $_POST[''] not $_Post[''].
if(isset($_POST['Update'])){
$UpdateFName = $_POST['FirstName'];
$UpdateLName = $_POST['LastName'];
$UpdateEmail = $_POST['Email'];
$UpdateUName = $_POST['UserName'];
$UpdatePassword = $_POST['Password'];
$sql = $con->query("
UPDATE BD SET
FirstName = '$UpdateFName',
LastName = '$UpdateLName',
Email = '$UpdateEmail',
UserName = '$UpdateUName',
Password = '$UpdatePassword'
WHERE
ID= '$User'"
);
header('Location: update.php');
}
Upvotes: 4
Reputation: 21
First of all you should include your error, and second, you don't have to use curly braces for the query try it without them.
Upvotes: 0