Page 1 of 1

combine field contents on submission - syntax issue

Posted: Mon Aug 15, 2011 4:07 pm
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?

Re: combine field contents on submission - syntax issue

Posted: Mon Aug 15, 2011 4:23 pm
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;
}

Re: combine field contents on submission - syntax issue

Posted: Mon Aug 15, 2011 4:52 pm
by inosent1
thanks!!!!!