Page 1 of 1

PHP variable default value

Posted: Wed Jan 04, 2012 1:52 pm
by ubiratan
friends,

I do not know practically nothing of PHP, I would rely on help from friends of the forum.

In the code below would like to bring the variable UF loaded with a default value, EXAMPLE: UF = "PR"

/></td>
<td >UF:<br />
<input name="uf" title="Informe o estado" type="text" class="campoCadastro" id="uf" value="<?=$_POST['uf']?>" maxlength="2" style="width:25px;
<?php
$nomeCampoVerifica = "uf";
if($_POST["ACAO"]=="novoCadastro" && $_POST[$nomeCampoVerifica]==""){?>
border:1px #F00 solid;
<?php }; ?>"
/></td>

Muito obrigado

Re: PHP variable default value

Posted: Wed Jan 04, 2012 3:17 pm
by social_experiment

Code: Select all

<?php
 $uf = 'topic';

 // will echo UF: topic
 echo 'UF: ' . $uf;
?>
Hth

Re: PHP variable default value

Posted: Wed Jan 04, 2012 3:41 pm
by ubiratan
thanks for replying.

only blank, something like this:

<?php
if empty($UF){
$uf = 'topic';
}
// will echo UF: topic
echo 'UF: ' . $uf;
?>

Re: PHP variable default value

Posted: Thu Jan 05, 2012 12:34 am
by social_experiment
You can also define $UF if you want; uppercase letters are normally used for constants and if you do have $UF and $uf they are 2 different variable as variable names in php are case-sensitive.
http://www.php.net/manual/en/language.v ... basics.php