How display record from database?

At any time to me can come the data (POST method). I take them and write to the database — everything works, data is entered in the database . The database table consists of id autoincremental and blabla.

Then I have these same data that is written to blabla will automatically display on the page. I do not understand how to do this?

While there is such code:
$result = $mysqli->query ("SELECT blabla FROM table WHERE id=(SELECT max(id) from table)"); // query — it works, gives the latest record.
echo $result;// print data

/* free result set */

Specially sent data they have recorded in the database, then refreshes the page, but it's empty.
What is the error?
July 2nd 19 at 18:20
3 answers
July 2nd 19 at 18:22
Obviously because in $result You have to be is not the text, and the result object of the query.
$row = $result->fetch_assoc();
echo $row['blabla'];
Does not work:
$result = $mysqli->query ("SELECT blabla FROM table WHERE id=(SELECT max(id) from table)"); // query
$row = $result->fetch_assoc();
echo $row['blabla'];// print data

 /* free result set */
- karine_Pacoc commented on July 2nd 19 at 18:25
July 2nd 19 at 18:24
View that displays
echo '<pre>'; 
echo '</pre>';
Nothing displays - karine_Pacoc commented on July 2nd 19 at 18:27
Okay, I'll do another way. Thank you. - karine_Pacoc commented on July 2nd 19 at 18:30
July 2nd 19 at 18:26
In General You have suggested is correct (at least logically correct) solution. But personally, I see You have two key points:

1. Why do You need to get data from the database that have just to the same and recorded? Moreover, such relatively perverse way, and even more 2 query (query + subquery). If you want to get the last record from the database, a query like:
So we get the last record, not the one we put there, and the one that will physically last at the time of query execution that is completely identical to Your version, but in 1 query (no subqueries).

There is another option of the query in one request:
According to this variant, can't say for sure that we will get the last existing record in the database at the time of the query, or specifically, the last record we inserted in the DB... but it works definitely not worse than Your example :)

1.1. Why don't we just output the data that we just recorded in the database? It's just the same data that we need, but they have already received.

2. Usually, in this situation, give the output of var_dump() (or similar functions) to understand why data are not displayed. But to understand this, we must first acknowledge that we have a variable at all... at least it can help other developers, and You can more accurately formulate a question, for example, "it was expected that the result will be a scalar type and there is some reason the cursor of query result from database". That is,
//instead of
echo $result;</code-->
<br / > - greatly facilitate the solution of such problems in the future.
It is too hard for me :D hate php with sql. Will make in another way. Thank you. - karine_Pacoc commented on July 2nd 19 at 18:29

Find more questions by tags Web DevelopmentMySQLPHP