Notice: Array to string conversion in update musqli

31
January 13, 2019, at 09:40 AM

I want to run an update query via mysqli in php. Here's my code:

$idget = $_GET['id'];
include_once ('config.php');
$sqlselected = "SELECT * FROM student WHERE id='$idget' ";
$resaul = mysqli_query($cont,$sqlselected);
$row = mysqli_fetch_assoc($resaul);
//var_dump($row);
if (isset($_POST['btn'])){
    $data = $_POST['frm'];
    // var_dump($data);
    //  echo $data['name'];
    $sqlupdate = "UPDATE student SET name ='$data=[name]' WHERE id=$idget ";
    mysqli_query($cont,$sqlupdate);
}

But I'm getting this error on update mysql:

Notice: Array to string conversion in update musqli

What am I doing wrong? How can I fix it?

Answer 1

first at all https://stackoverflow.com/a/60496/10748309

you can try

"UPDATE student SET name =$data=[`name`] WHERE id=$idget";
Answer 2

Try changing $sqlupdate = "UPDATE student SET name ='$data=[name]' WHERE id=$idget ";

to $sqlupdate = "UPDATE student SET name ='".$data=["name"]."' WHERE id=$idget ";

I think it is because of the name index in $data=[name] does not have quotes or apostrophes.

Answer 3

i don't know the value of $data = $_POST['frm']; but i think that is a string and not array, in this case use : $sqlupdate = "UPDATE student SET name ='$data' WHERE id=$idget ";

if the value of $data = $_POST['frm']; is a array try this: $sqlupdate = "UPDATE student SET name ='".$data['name']."' WHERE id=$idget ";

READ ALSO
How to check whether a value exists in an array that is stored in the database

How to check whether a value exists in an array that is stored in the database

I have a database where moments contain a user id and friend id'sThe friend_ids are saved as an array

33
How to count number of rows while using UNION in codeigniter?

How to count number of rows while using UNION in codeigniter?

In this question, I have two tables table1 and table2 where the tables structure of both are sameNow, I want to count number of rows

44
Errors installing IPSearch from GitHub

Errors installing IPSearch from GitHub

I got some few errors while installing IPSearch package from GitHub, that I couldn't solve with the answers of other people, in other forums too, so I was hoping that some of you could suggest solutions to the problems below

14
Is it possible to do a group_concat inside another group_concat?

Is it possible to do a group_concat inside another group_concat?

I'm building a webshop that sells shoesI'm trying to write a command that will show the quantity of each size for 1 specific sneaker

49