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
https://forums.phpfreaks.com/topic/9562-help-with-variable/
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
https://forums.phpfreaks.com/topic/9562-help-with-variable/#findComment-35395
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
https://forums.phpfreaks.com/topic/9562-help-with-variable/#findComment-35419
Share on other sites

Archived

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

×
×
  • 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.