genista Posted April 14, 2007 Share Posted April 14, 2007 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 Link to comment https://forums.phpfreaks.com/topic/47024-solved-problem-with-undefined-variable-in-function/ Share on other sites More sharing options...
MadTechie Posted April 14, 2007 Share Posted April 14, 2007 <?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 Link to comment https://forums.phpfreaks.com/topic/47024-solved-problem-with-undefined-variable-in-function/#findComment-229332 Share on other sites More sharing options...
genista Posted April 14, 2007 Author Share Posted April 14, 2007 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 Link to comment https://forums.phpfreaks.com/topic/47024-solved-problem-with-undefined-variable-in-function/#findComment-229339 Share on other sites More sharing options...
Guest prozente Posted April 14, 2007 Share Posted April 14, 2007 add isset <?php if (isset($beautician) && $beautician == "true"){echo "checked=\"checked\"";}?> Link to comment https://forums.phpfreaks.com/topic/47024-solved-problem-with-undefined-variable-in-function/#findComment-229344 Share on other sites More sharing options...
genista Posted April 14, 2007 Author Share Posted April 14, 2007 Thanks! Worked perfectly Link to comment https://forums.phpfreaks.com/topic/47024-solved-problem-with-undefined-variable-in-function/#findComment-229364 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.