combine field contents on submission - syntax issue

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
inosent1
Forum Commoner
Posts: 97
Joined: Wed Jan 28, 2009 12:18 pm

combine field contents on submission - syntax issue

Post by inosent1 »

when i submit a form, i want to check to see if a particular condition is present, then i want to have another field in the DB filled in with the contents of more than one field.

if i use only one field (instrument1 is the field i want populated), then everything works great, but when i add a second field (or third/fourth etc ... as the case requires) i either get some strange extraneous characters in instrument1, or, in the example below it only posts the contents of lsrc

Code: Select all

$lsrc = mysql_real_escape_string($_POST['lsrc']);

if ($lsrc == "HOME") {
	$instrument1 = $lsrc AND $b_fname;
} else {
	$instrument1 = $b_fname;
}




how can i combine fields so they both successfully input to (in the above example) instrument1?
oscardog
Forum Contributor
Posts: 245
Joined: Thu Oct 23, 2008 4:43 pm

Re: combine field contents on submission - syntax issue

Post by oscardog »

Simples...

Code: Select all

$lsrc = mysql_real_escape_string($_POST['lsrc']);

if ($lsrc == "HOME") {
        $instrument1 = $lsrc . $b_fname;
} else {
        $instrument1 = $b_fname;
}
You can use that as many times as you need and add characters in between if you wish, for example it's common to separate things with commas. I don't know how bothered you're about 'code standards' but it's fairly common practise to name variables like I did below with $anotherVariableToAdd.

Code: Select all

$lsrc = mysql_real_escape_string($_POST['lsrc']);

if ($lsrc == "HOME") {
        $instrument1 = $lsrc . ', ' . $b_fname . ', ' . $anotherVariableToAdd;
} else {
        $instrument1 = $b_fname;
}
inosent1
Forum Commoner
Posts: 97
Joined: Wed Jan 28, 2009 12:18 pm

Re: combine field contents on submission - syntax issue

Post by inosent1 »

thanks!!!!!
Post Reply