Jump to content

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

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.