Get each line from textarea

Hi,
my code works for one line input but Im trying to get multiple lines in a Textarea post and that does not work. for example if I search " robin " it searches for robin and it works but if I search " robin [newline] rico [newline] charly " it does not work

This is the code so far:

[php]

<?php $db = new mysqli('localhost', 'root', 'root', 'root'); session_start(); if(isset($_POST['submit'])) { $textarea = trim($_POST['search']); $search = explode("\n", $textarea); $search = array_filter($search, 'trim'); // remove any extra \r characters left behind $_SESSION['firstname']= $textarea; if(($_SESSION['firstname'])!="") { header("location:index.php"); }else{ echo ""; } } if(($_SESSION['firstname']!="")) { foreach($search as $data){ $data = $_SESSION['firstname']; $view = $db->query("SELECT * FROM contacts WHERE firstname REGEXP '$data'"); $check = mysqli_num_rows($view); } if($check!="") { while($output = mysqli_fetch_object($view)) { ?>

<?php echo $output->firstname; ?>

<?php echo $output->lastname; ?>


<?php } } else { ?>

Error: Add new data enter and check the correct keyword

<?php } } ?> [/php]

I also tried using " $search = explode(’\n’, $_POST[‘search’]); " but somehow could not get it to work or used it wrong. Could any one tell me what am i doing wrong or missing?
Thanks for any help :slight_smile:

I got my code somehow working now :slight_smile:
[php]

<?php session_start(); ?> <?php $db = new mysqli('localhost', 'root', 'root', 'skfstapel'); if(isset($_POST['submit'])) { $textarea = trim($_POST['search']); $search = implode("|",explode("\r\n", $textarea)); $_SESSION['firstname']= $textarea; } if(($_SESSION['firstname']!="")) { $view = $db->query("SELECT * FROM contacts WHERE firstname REGEXP '$search'"); while($output = mysqli_fetch_array($view)) { ?>

<?php echo $output['firstname']; ?> <?php echo $output['lastname']; ?>


<?php } } else { ?>

<?php echo $output['firstname']; ?> <?php echo $output['lastname']; ?>

<?php } ?> [/php]

One thing I cant seem to get working is to output the textarea field even if no data is found in the database.
Something like this:
Database values:
Data1 - description - image
Data2 - description - image
Data3 - description - image

Now if someone searches for:
Data1
Data2
Data4

the output should look somehting like this:
Name - description - image - Data1 (textarea value)
Name - description - image - Data2 (textarea value)
Name - description - image - Data4 (textarea value even if not found)

I hope this is somehow understandable ;D
I appreciate any help :wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service