3 textfields (several words inside) - make 1 PHP variable ??

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Calimero
Forum Contributor
Posts: 310
Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way

3 textfields (several words inside) - make 1 PHP variable ??

Post by Calimero »

If I have 3 textfields in a form named: tf1, tf2 and tf3, and user inserts some words inside each (lets say 3 or more), whats the PHP code to make all 3 textfields, all words inside - together to be inserted in one MySQL field, NOTE Sql code I know how to write, if all those ex. 9 words can be represented as one variable...

Anyone, help,... And of course THANK YOU :D
Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Post by Straterra »

You could concatinate (forgive my spelling). This simply means to add 2 string together. I would add the strings together, and put a special character inbetween each string, so you know how to get eat string by its self again. To add two strings together, you just use the period (.) .
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

Code: Select all

<?php
$together = $field1.$field2.field3;
// you can also do
$together = "$field1 $field2 field3";
//or implode them 
$fields = array ($field1, $field2, $field3);
$separator = "||"; //separe each piece with two |'s
$together = implode($separator, $array)
?>
Post Reply