Jump to content


Photo

Help with Variable


  • Please log in to reply
3 replies to this topic

#1 jingato

jingato
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 12 May 2006 - 09:29 PM

Hi. I have a form that a user fills out and submits. I made a new variable on the page it is submittd to to combine The two address lines into one, seperated by a comma. I used this code for that

$Property_Address = $_POST["Property_Address1"] . ", " . $_POST["Property_Address2"];

That works fine as it is, But I would like to know if there is a way I can make it leave the comma out if the Property_Address2 field was blank when submitted. I meesed around with the if else statement for the last hour, but could only get errors back. I'm pretty new to php so your help is appreciated.

Thanks

John

#2 Caesar

Caesar
  • Members
  • PipPipPip
  • Advanced Member
  • 1,025 posts

Posted 12 May 2006 - 09:38 PM

You mean, something like this: ?

$addr_1 = $_POST['Property_Address1'];

$addr_2 = $_POST['Property_Address2'];

if($addr_2 == '')

{$Property_Address = $addr_1;}

else

{$Property_Address = $addr_1.",".$addr_2;}

PHP Ninja

#3 jingato

jingato
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 13 May 2006 - 05:19 AM

[!--quoteo(post=373326:date=May 12 2006, 05:38 PM:name=Caesar)--][div class=\'quotetop\']QUOTE(Caesar @ May 12 2006, 05:38 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
You mean, something like this: ?

$addr_1 = $_POST['Property_Address1'];

$addr_2 = $_POST['Property_Address2'];

if($addr_2 == '')

{$Property_Address = $addr_1;}

else

{$Property_Address = $addr_1.",".$addr_2;}
[/quote]


Thanks man! It worked perfect.

#4 448191

448191
  • Staff Alumni
  • Advanced Member
  • 3,545 posts
  • LocationNetherlands

Posted 13 May 2006 - 07:10 AM

Cleaner: make $_POST['Property_Adress'] an array in your form (use []), and:
$propertyAdress = implode(', ',$_POST['Property_Adress']);

The power of arrays.. [img src=\"style_emoticons/[#EMO_DIR#]/laugh.gif\" style=\"vertical-align:middle\" emoid=\":laugh:\" border=\"0\" alt=\"laugh.gif\" /]
Nothing more to it.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users