我正在尝试在我的表格中获取更新信息。我花了几个小时,继续在圈子里。我认为问题出在我的查询部分的代码末尾。任何帮助,将不胜感激。感谢。
<?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');
}
?>
答案 0 :(得分:4)
您错误地使用了post方法。您应该使用$ _POST [&#39;&#39;]而不是$ _Post [&#39;&#39;]等帖子方法。
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');
}
答案 1 :(得分:1)
<?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');
}
答案 2 :(得分:0)
首先,你应该包含你的错误,其次,你不必使用大括号进行查询,不用它们就可以试试。