jingato Posted May 12, 2006 Share Posted May 12, 2006 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.ThanksJohn Quote Link to comment Share on other sites More sharing options...
Caesar Posted May 12, 2006 Share Posted May 12, 2006 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 Link to comment Share on other sites More sharing options...
jingato Posted May 13, 2006 Author Share Posted May 13, 2006 [!--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. Quote Link to comment Share on other sites More sharing options...
448191 Posted May 13, 2006 Share Posted May 13, 2006 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.