Jump to content

Help with Variable


jingato

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
Link to comment
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.
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.