Jump to content

Archived

This topic is now archived and is closed to further replies.

jingato

Help with Variable

Recommended Posts

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

Share this post


Link to post
Share on other sites
You mean, something like this: ?

[code]$addr_1 = $_POST['Property_Address1'];

$addr_2 = $_POST['Property_Address2'];

if($addr_2 == '')

{$Property_Address = $addr_1;}

else

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

Share this post


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

[code]$addr_1 = $_POST['Property_Address1'];

$addr_2 = $_POST['Property_Address2'];

if($addr_2 == '')

{$Property_Address = $addr_1;}

else

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


Thanks man! It worked perfect.

Share this post


Link to post
Share on other sites
Cleaner: make $_POST['Property_Adress'] an array in your form (use []), and:
[code]$propertyAdress = implode(', ',$_POST['Property_Adress']);[/code]

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.

Share this post


Link to post
Share on other sites

×

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.