# Retrieve(echo) data

**URL:** <https://www.phphelp.com/t/retrieve-echo-data/34265>\
**Category:** Uncategorized\
**Created:** [November 15, 2021, 2:37am UTC](https://www.phphelp.com/t/retrieve-echo-data/34265 "2021-11-15T02:37:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mekaboo](https://www.phphelp.com/letter_avatar_proxy/v4/letter/m/7ea924/32.png) [@Mekaboo](https://www.phphelp.com/u/Mekaboo)\
**Post date:** [November 15, 2021, 2:37am UTC](https://www.phphelp.com/t/retrieve-echo-data/34265/1 "2021-11-15T02:37:44Z")

</div>

Hey 😊

```auto
<?php
$comment = filter_input(INPUT_GET, 'comment');
if (!empty($comment)){
$host = "";
$dbusername = "";
$dbpassword = "";
$dbname = "";
// Create connection
$conn = new mysqli ($host, $dbusername, $dbpassword, $dbname);
if (mysqli_connect_error()){
die('Connect Error ('. mysqli_connect_errno() .') '
. mysqli_connect_error());
}
else{
$sql = "INSERT INTO comment(comment)
values ('$comment')";
if ($conn->query($sql)){
echo "New record is inserted sucessfully";
}
else{
echo "Error: ". $sql ."
". $conn->error;
}
$conn->close();
}
}
else{
echo "Comment should not be empty";
die();
}
?>
         
         
         
         <?php

$result = mysqli_query("SELECT comment FROM comment"); 
?>
     <p><?php echo $GET["comment"]; ?></p>
        </div>
  </div> 

```

**The data submitted from the attached form is stored within my DB. Issue is retrieving that data (echo) so it can display. Where in this code do I change it so the echo works properly?**

Thank ya ❤

---

<div class="post-metadata">

**Author:** ![ErnieAlex](https://www.phphelp.com/letter_avatar_proxy/v4/letter/e/bc8723/32.png) [@ErnieAlex](https://www.phphelp.com/u/ErnieAlex)\
**Post date:** [November 15, 2021, 2:22pm UTC](https://www.phphelp.com/t/retrieve-echo-data/34265/2 "2021-11-15T14:22:50Z")

</div>

Well, a SELECT query is just the query to set up the database to retrieve data from.  
It is designed so that you can get just one record or millions from the same table.  
Once the SELECT is created, you then need to FETCH the data to be able to use it.  
You are missing a FETCH command. Here is a site that explains it in simple terms.  
I think you should start there. Also, you should learn how to indent your code which  
will make it more readable. Good luck! [Select Example](https://www.w3schools.com/php/php_mysql_select.asp)

---

<div class="post-metadata">

**Author:** ![Mekaboo](https://www.phphelp.com/letter_avatar_proxy/v4/letter/m/7ea924/32.png) [@Mekaboo](https://www.phphelp.com/u/Mekaboo)\
**Post date:** [November 15, 2021, 7:49pm UTC](https://www.phphelp.com/t/retrieve-echo-data/34265/3 "2021-11-15T19:49:02Z")

</div>

@ErnieAlex 😊

Ive tried the SELECT query and it doesn’t work for me. I don’t know how to connect both SELECT and INSERT. How do I take my code that I posted and connect the dots because I must not be connecting it right

---

<div class="post-metadata">

**Author:** ![ErnieAlex](https://www.phphelp.com/letter_avatar_proxy/v4/letter/e/bc8723/32.png) [@ErnieAlex](https://www.phphelp.com/u/ErnieAlex)\
**Post date:** [November 15, 2021, 8:02pm UTC](https://www.phphelp.com/t/retrieve-echo-data/34265/4 "2021-11-15T20:02:30Z")

</div>

Again, Mekaboo, you did a SELECT, but, that just acquires a LIST of items. You still need to FETCH the items. Did you read the example I linked to? I clearly shows how to SELECT and then FETCH the data.

> [@Mekaboo](#):
>
> `$result = mysqli_query("SELECT comment FROM comment"); `

This is just one select, no fetch. You need to add a fetch. Loosely like this:

```auto
$result = mysqli_query("SELECT comment FROM comment");
$row = $result->fetch_assoc())

```

But, normally, you first check to make sure it actually retrieved data from the query. All of that is in the example link I posted for you to review. You should read that.
