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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.