Jump to content

Get multiple form values from one input box


BrendanmPHP

Recommended Posts

I have a textarea feild in my form where the user can type in several keywords such as

 

Textarea Box Below

 

Cars

Trains

Buses

 

I have a database with the meanings of the words entered and want to be able to get the three definitions from the database on for submission.

 

In a normal input box where i only type one word i can grab no problem like so

 

$word = $_POST['word'];

$sql = "SELECT meaning FROM table WHERE word='$word'";

 

Though i am trying to get multiple values from the same textarea box

 

So if a user types in 3 words the query would query the database on thoses three words, the problem is i dont know how to get the diffrent words from the form

 

for example

 

$first = $_POST['word']; which would be the first word

$sec = $_POST['word']; which would be the second word etc.

 

Any help here would be great thanks.

I tried this

 

if ($_POST['submit']){

 

$text = $_POST['ta'];

 

$words = explode(" ", $text);

echo $words[0];

 

 

}

 

Though that still outputs all the words instead of word 1

 

or

 

echo $words[1];

 

Still echos all the words instead of the 2nd word.

 

EDIT

 

i changed the explode to $words = explode(".", $text);

 

and seperated my words with a . which works great

 

Though how would i query all the words at once to return the 3 seperate meaning?

 

I can do where word=$word1 AND $word2 etc

 

Because sometimes there will be more words entered than other times.

Try this query string (changed to your particular needs, obviously)

 

$query = "SELECT `field1`, `field2`, `field3` FROM `table` WHERE `some_field` IN(" . implode( ',', $words) . ")";

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.