# Nl2br() How to call it when viewing textarea data in database

**URL:** <https://www.phphelp.com/t/nl2br-how-to-call-it-when-viewing-textarea-data-in-database/36238>\
**Category:** Beginners - Learning PHP\
**Created:** [August 7, 2024, 12:43am UTC](https://www.phphelp.com/t/nl2br-how-to-call-it-when-viewing-textarea-data-in-database/36238 "2024-08-07T00:43:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mike2](https://www.phphelp.com/letter_avatar_proxy/v4/letter/m/e9a140/32.png) [@Mike2](https://www.phphelp.com/u/Mike2)\
**Post date:** [August 7, 2024, 12:43am UTC](https://www.phphelp.com/t/nl2br-how-to-call-it-when-viewing-textarea-data-in-database/36238/1 "2024-08-07T00:43:59Z")

</div>

Textarea list of Names inserted into the database from form is OK ,everything works accept searching for anything more than 1st entry in the textarea then i get nothing is found. Looks like one big string that needs to broken to search for the other names is the goal. Again only one name entered into the textarea it is found more than one entry nothing found.

Did some research seems that what I want to accomplish is found with this PHP function. There’s a function called nl2br(). Use it when echoing data, not when inserting to database. Now the question becomes how to call that function while viewing data from the textarea that was inserted into the database. looks like a viewing problem ? since everything works accept searching for anything more than 1st entry in the textarea then nothing is found. Need some help on the query with function called of nl2br( ) should work. Thanks to all who for any help and for any answers.

---

<div class="post-metadata">

**Author:** ![phdr](https://www.phphelp.com/letter_avatar_proxy/v4/letter/p/91b2a8/32.png) [@phdr](https://www.phphelp.com/u/phdr)\
**Post date:** [August 7, 2024, 1:18am UTC](https://www.phphelp.com/t/nl2br-how-to-call-it-when-viewing-textarea-data-in-database/36238/2 "2024-08-07T01:18:19Z")

</div>

It’s not clear if you have a search problem or a problem displaying something.

If you are storing multiple values in a single column in a database table, that is a bad design. You should store data one row per value. If you are entering a multiple word search term and want to find data that matches any of the words, you would explode the search term and dynamically build a WHERE … clause to try to match any of the individual words.

So, post an example of what your database table data is, what you are submitting from the form, and what result you expect.

---

<div class="post-metadata">

**Author:** ![Mike2](https://www.phphelp.com/letter_avatar_proxy/v4/letter/m/e9a140/32.png) [@Mike2](https://www.phphelp.com/u/Mike2)\
**Post date:** [August 7, 2024, 2:18am UTC](https://www.phphelp.com/t/nl2br-how-to-call-it-when-viewing-textarea-data-in-database/36238/3 "2024-08-07T02:18:34Z")

</div>

The input box , then just press enter to insert into database

```auto
  <div class="form-group">
	<p>		  
            <label for="Name">Custumers</label>
		    <textarea class="form-control rounded-0" id="candidate" name="custumer" pattern="^[a-zA-Z\s]*$" style="white-space: pre-wrap >multi-line text" placeholder="Your Name Here" rows='10' cols='40'required title ="Write Your Name. "></textarea> 	 	
		</p>
	          </div>

The insert to database after connection

$query = $this->db->prepare('INSERT INTO custumers, ip) VALUES (name)');
   	$query->bindParam(':name', $name);  
          $query->execute();
        $id = $this->db->lastInsertId();
        return $id;
      }
      catch(PDOException $e) {
        //echo "Error: " . $e->getMessage();
        //exit();
        return false;
      }
     }
  }
```

This is the search window for input

```auto
<div class="col-lg-4">
                <form name="f1" method="GET">
                <div class="form-group">
                    <label>Search by name</label>
                    <input class="form-control" type="text" values="<?php echo nl2br($name);?>"name="name"  
```

For reference maybe something like this may work for what I trying to do

> **[How to insert data from Texarea to Database in PHP - Phptpoint.com](https://www.phptpoint.com/insert-data-from-textarea-to-database/)**
>
> How to insert data from textarea to database using php mysqli. You need a textarea with a submit button. Now get the value entered in textarea on php script. connect with db and save data.

Thank you for your help and time

---

<div class="post-metadata">

**Author:** ![Mike2](https://www.phphelp.com/letter_avatar_proxy/v4/letter/m/e9a140/32.png) [@Mike2](https://www.phphelp.com/u/Mike2)\
**Post date:** [August 7, 2024, 2:28am UTC](https://www.phphelp.com/t/nl2br-how-to-call-it-when-viewing-textarea-data-in-database/36238/4 "2024-08-07T02:28:06Z")

</div>

[quote=“Mike2, post:1, topic:36238”]  
Again only one name entered into the textarea it is found more than one entry nothing found.

---

<div class="post-metadata">

**Author:** ![Mike2](https://www.phphelp.com/letter_avatar_proxy/v4/letter/m/e9a140/32.png) [@Mike2](https://www.phphelp.com/u/Mike2)\
**Post date:** [August 7, 2024, 2:36am UTC](https://www.phphelp.com/t/nl2br-how-to-call-it-when-viewing-textarea-data-in-database/36238/5 "2024-08-07T02:36:10Z")

</div>

> [@phdr](#):
>
> multiple values in a single column in a database table

Yes it is what i want multiple values in a single column in a database table and entering a multiple word search term and want to find data that matches any of the words. That is exactly what I want.

I am new to php programming and I thought the function called nl2br(). would do just that ?

---

<div class="post-metadata">

**Author:** ![Strider64](https://www.phphelp.com/user_avatar/www.phphelp.com/strider64/32/3161_2.png) [@Strider64](https://www.phphelp.com/u/Strider64)\
**Post date:** [August 8, 2024, 9:20pm UTC](https://www.phphelp.com/t/nl2br-how-to-call-it-when-viewing-textarea-data-in-database/36238/6 "2024-08-08T21:20:20Z")

</div>

All nl2br does is inserts HTML line breaks before all newlines in a string. It looks like you’re confusing inserting and reading from a database table also.
