[英]How to solve Array to String conversion error in php?
When I run this code, it returns True but along with that it gives an Array to string conversion error . 当我运行此代码时,它返回True,但同时会给出Array到字符串的转换错误 。 I have seen other answers but I couldn't find the problem in this code. 我看到了其他答案,但在此代码中找不到问题。 It gives error on query line. 它在查询行上给出错误。
<?php
$id = ['id'];
$name = $_POST["name"];
$email = $_POST["Email"];
$mobile = $_POST["MobileNo"];
$password = $_POST["Password"];
$result = mysqli_query($conn, "UPDATE sign_up SET full_name = '$name', email = '$email', phone_official = '$mobile', password ='$password'where idsign_up='$id'");
$res = array();
// /$res['id'] = 0;
if ($result) {
$res['check'] = true;
$res['message'] = 'Data Updated..';
// /$res['id'] = mysqli_insert_id($conn);
}
else {
$res['check'] = false;
$res['message'] = 'There was an Errorr!';
// /$res['message'] = $emailErr;
}
header('Content-Type: application/json');
echo json_encode($res);
Firstly I would advise to look into PDO, as your scripts are vulnerable for injections now. 首先,我建议您研究PDO,因为您的脚本现在容易受到注入的攻击。 Information on PDO from PHP.net 来自PHP.net的PDO信息
To solve your error I think it would be as easy to change the first line of code. 为了解决您的错误,我认为更改代码的第一行会很容易。 It says now: 现在说:
$id=['id'];
You might wanted to have a $_GET or $_POST, but in this form it won't work for sure. 您可能想要$ _GET或$ _POST,但是以这种形式肯定不能正常工作。 If the ID is in the URL I guess it would become: 如果ID在URL中,我想它将变成:
$id=$_GET['id'];
If that doesn't solve it please share the error code with line numbers. 如果仍不能解决问题,请与行号共享错误代码。
But again, look into PDO because this script is really vulnerable. 但是再次,请查看PDO,因为此脚本确实很容易受到攻击。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.