Jump to content

Re-assigning variable with if else


perficut

Recommended Posts

First let me apologise for such a basic command, but I need a little help with the syntax.

I have a number of variables passed into the php file from a form. I want to check and see if var#1 is left blank, if so leave var#2 alone. If  not then var#2 has the same data as var#1

Ex:
if Var#1 = " " then nothing happens
else if Var#1 has data, then Var#2 is now = Var#1


Var#2 is a persons home address
Var#1 is a persons billing address

There is always data in Var#2, thier home address, but if the billing address has filled out, then I want the Var containing their home address to now be their billing address.

If any of this makes sense. - Heck, I'm confused if I dont think slow about it. But this is probably an easy remedy.

THANKS
Link to comment
Share on other sites

[code]<?php

// the action='' value in your html form leads to here
// assuming the name of the input where your home address goes is called home_address
$home_address = $_POST['home_address'];

// assuming same as above but billing address is called billing_address
$billing_address = $_POST['billing_address'];

// now let's check
if(strlen($billing_address))
{
$home_address = $billing_address;
} else {
// don't do anything, thanks
}

// continue our processing
// let me make this clear, if someone enters a blank space in the billing address, you'll have virtually a string in both variables
// but literally, nothing in both

?>[/code]
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.