Recoverable error fatal error: Object of class mysqli_result could not be converted to string

Asked

Viewed 3,628 times

0

I am unable to save the ID of the address in the bank, I select the address but I can’t

<?php

session_start();


$host = "localhost";
$user = "root";
$senha = "";
$banco = "cafeteriasp";
$conexao = mysqli_connect ($host, $user, $senha) or die (mysql_error());
mysqli_select_db($conexao, $banco) or die (mysql_error());

$end = mysqli_query ($conexao, "select ENDID FROM enderecos order by ENDID desc limit 1") or die(mysqli_error());
$id = $_SESSION['id'];


$numero = $_POST['numero'];
$complemento = $_POST['complemento'];



$insert = mysqli_query($conexao, "INSERT INTO end_usu(END_USU, END_ID, END_NUMERO, END_COMPLEMENTO)
VALUES ('$id', '$end', '$numero', '$complemento')");



mysqli_close($conexao);
?>

1 answer

0


You missed processing the query and extracting the result. You cannot pass a resouce directly into a string you need to extract the result first with the function mysqli_fetch_assoc() it returns an associative array that must be passed in Insert, remember to indicate the key you want to get the value, in case ENDID

Change your code to:

$end = mysqli_query ($conexao, "select ENDID FROM enderecos order by ENDID desc  limit 1")
or die(mysqli_error($conexao));

$endereco = mysqli_fetch_assoc($end);

//código omitido.


$insert = mysqli_query($conexao, "INSERT INTO end_usu(END_USU, END_ID, END_NUMERO, END_COMPLEMENTO) VALUES ('$id', '{$endereco['ENDID']} ', '$numero', '$complemento')");
  • 1

    Do you have a problem with the answer?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.