gpt4 book ai didi

php - 尝试发送UPDATE查询时,无法将mysqli_result类的对象转换为字符串

转载 作者:行者123 更新时间:2023-11-29 20:53:01 25 4
gpt4 key购买 nike

我正在尝试只向表发送UPDATE查询,以为用户设置一个值,


  可捕获的致命错误:在第19行的E:\ web \ nginx \ html \ b1is \ profile.php中,类mysqli_result的对象无法转换为字符串


我不希望返回任何值,除非可以进行查询。

码:

<?php
ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);
session_start();
$sqlcon = include_once 'dbconnect.php';

if(!isset($_SESSION['user']))
{
header("Location: login.php");
}
$res=mysqli_query($sqlcon,"SELECT * FROM users WHERE user_id=".$_SESSION['user']);
$userRow=mysqli_fetch_array($res);

if(isset($_POST['updprof']))
{
$steamid = mysqli_real_escape_string($sqlcon,$_POST['steamid']);
$discordid = mysqli_real_escape_string($sqlcon,$_POST['discordid']);
if(isset($steamid))
{
if(!mysqli_query($sqlcon,"UPDATE users SET steamid = '$steamid' WHERE user_id = $res"))
{
?> <script>alert("Update couldn't be made")</script> <?php
}
}

if(isset($discordid))
{
if(!mysqli_query($sqlcon,"UPDATE users SET discordid = '$discordid' WHERE user_id = $res"))
{
?> <script>alert("Update couldn't be made")</script> <?php
}
}
}
?>

最佳答案

$res=mysqli_query($sqlcon,"SELECT * FROM users WHERE user_id=".$_SESSION['user']);
^^^---mysqli object

if(!mysqli_query($sqlcon,"UPDATE users SET steamid = '$steamid' WHERE user_id = $res"))
string context----^^^


您不能将mysql结果对象/句柄直接传递给另一个查询。您必须先从结果中获取一个值,然后再使用该值。

关于php - 尝试发送UPDATE查询时,无法将mysqli_result类的对象转换为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37869481/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com