[英]PHP SQL update query
I am attempting to update SQL. 我正在尝试更新SQL。
I suspect that the issue is either with my sql query , or with my connection. 我怀疑问题出在我的SQL查询或我的连接上。 Although, I could be totally wrong. 虽然,我可能完全错了。
Apologies if it's messy, but I'm using console.log
to attempt to debug the issue, and the console output is: 道歉,如果它很乱,但我正在使用console.log
来尝试调试问题,而控制台输出是:
B.1
B.2
D.1
D.2
D.3
B.2.1
B.5
In relation to sql queries , amongst others, I've attempted with the following two: 关于sql查询 ,除其他外,我尝试了以下两个:
$sql = "UPDATE Users SET description = " . '$description' . "WHERE userID = " . '$this->userID';
$sql = "UPDATE Users SET description = '$description' WHERE userID = '$this->userID'";
edit-profile-handler.php 编辑配置文件- handler.php
<?php
if(isset($_POST['edit-profile-button'])) {
$description = $_POST['edit-description'];
echo '<script>console.log("B.1")</script>';
if(isset($description)) {
echo '<script>console.log("B.2")</script>';
$result = $user->updateDescription($description);
echo '<script>console.log("B.2.1")</script>';
}
if($result == true) {
echo '<script>console.log("B.4")</script>';
header("Location: profile.php");
}
echo '<script>console.log("B.5")</script>';
}
?>
User.php user.php的
<?php
class User {
private $con;
private $userID;
private $description;
public function __construct($con, $userID) {
$this->con = $con;
$this->userID = $userID;
$sql = "SELECT * FROM Users WHERE userID='$this->userID'";
$query = mysqli_query($this->con, $sql);
$user = mysqli_fetch_array($query);
$this->description = $user['description'];
}
public function getID() {
return $this->userID;
}
public function updateDescription($description) {
echo '<script>console.log("D.1")</script>';
$sql = "UPDATE Users SET description = '$description' WHERE userID = '$this->userID'";
echo '<script>console.log("D.2")</script>';
$result = mysqli_query($this->con, $sql);
echo '<script>console.log("D.3")</script>';
return $result;
echo '<script>console.log("D.4")</script>';
}
}
?>
Your $result
variable is not returning a BOOLEAN because it handles an UPDATE query result. 您的$result
变量未返回BOOLEAN,因为它处理UPDATE查询结果。
So on your updateDescription
function, try to return mysqli_affected_rows()
then try to check on edit-profile-handler.php
if $return > 0
it means there are row/s affected by your update. 所以在你的updateDescription
函数上,尝试返回mysqli_affected_rows()
然后尝试检查edit-profile-handler.php
如果$return > 0
则意味着你的更新会影响行/。 You can refer here. 你可以参考这里。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.