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

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.

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.

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

  <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

<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

Thank you for your help and time

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

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 ?

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.

Sponsor our Newsletter | Privacy Policy | Terms of Service