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
https://forums.phpfreaks.com/topic/31713-re-assigning-variable-with-if-else/
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]

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.