Jump to content

[SOLVED] Problem with undefined variable in function


genista

Recommended Posts

Hi,

 

I have a script with those good ol checkboxes and those good ol undefined variable errors when a checkbox is not checked. I have managed to fix this problem in all but one of my scripts where I use a function to update the database through an include. Here is the script:

 

//setup session etc 
//validating user input 
// This function is called from a functions include that does all //the database querying 
newuser($strUsername = isset($_POST['username']) ? $_POST['username'] : "", 
$strbeautician = isset($_POST['beautician']) ? $_POST['beautician'] : ""); 
?> 

//now for the html part: 

<tr><td>Beautician:</td><td><input type="checkbox" name="beautician" value="true" <?php if ($beautician == "true"){echo "checked=\"checked\"";}?> /> 
</td></tr> 

 

I have tried this in the function, but it did not work:

 

$stremail_address = isset($_POST['email_address']) ? $_POST['email_address'] : "",
	$strbeautician = if (!isset($_POST['beautician'])) {   
    $beautician = 'null';   
}else{ 
    $beautician = $_POST['beautician'];   
},  

 

This gives me Parse error: "parse error, unexpected T_IF"

 

 

Any help would be much appreciated,

 

 

G

<?php
$stremail_address = isset($_POST['email_address']) ? $_POST['email_address'] : "",





$strbeautician = if (!isset($_POST['beautician'])) {   
    $beautician = 'null';   
}else{ 
    $beautician = $_POST['beautician'];   
},  
?>

 

should be

 

<?php
$stremail_address = (isset($_POST['email_address'])) ? $_POST['email_address'] : "";

$beautician = (!isset($_POST['beautician'])) ? 'null' : $_POST['beautician'];  
?>

 

$beautician or $strbeautician

great thanks for that, I just have a problem on this bit of code no, with the error being undefined variable:

 

 

<tr><td>Beautician:</td><td><input type="checkbox" name="beautician" value="true" <?php if ($beautician == "true"){echo "checked=\"checked\"";}?> />
</td></tr>

 

 

Thanks,

 

G

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.