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

0

I am not able to save the Id of the address in the database, I do a select of the address but I can not

<?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);
?>
    
asked by anonymous 04.12.2017 / 14:38

1 answer

-1

The query failed to extract the result. You can not pass a resouce directly inside a string need to extract the result first with the function mysqli_fetch_assoc() it returns an associative array that must be passed in the insert, remember to indicate the key you want to get the value in ENDID p>

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')");
    
04.12.2017 / 14:41