AureliusR Posted March 16, 2013 Share Posted March 16, 2013 So I'm just learning PHP and MySQL for the first time, and I've been doing really well. I have a lot of experience with HTML and C++ so a lot of concepts are very familiar. I'm currently using if { to determine whether or not an HTML form field has any data in it or not. If either of two fields are empty, it echoes a warning to the user and re-prints the form on the resulting page. Here's a link to a pastebin of what I currently have. Note that I have tried $form_output both as 'true' and 'false' & also just as plain true and false (no quotes). Both seem to fail when I reach the if statements. Even if the $subject or $body variables are false, it still starts sending the emails in the if ($output_form = false) section. So my question is partially - does PHP recognize true and false without quotes as boolean variables? Or does it just think they are plain text? I figured that because they have no quotes, if it didn't recognize them as special terms it would crash the script at that point. I need to learn how to use a PHP debugger on Linux, so if someone could help me with that too, that'd be great. I probably wouldn't even have to ask this question because the debugger would have shown me what the script is actually doing. My other question is, the book I'm learning from shows the script going in and out of the <php? tags, back to HTML, then back into <php? to close the script (at the bottom of the above link). Is that accepted syntax or is that incorrect? Thanks a lot in advance for your help!! Much appreciated. Link to comment https://forums.phpfreaks.com/topic/275713-help-with-boolean-variables-and-going-in-and-out-of-tags/ Share on other sites More sharing options...
Jessica Posted March 16, 2013 Share Posted March 16, 2013 = is assignment. == is comparison. Link to comment https://forums.phpfreaks.com/topic/275713-help-with-boolean-variables-and-going-in-and-out-of-tags/#findComment-1418930 Share on other sites More sharing options...
Barand Posted March 16, 2013 Share Posted March 16, 2013 PHP booleans: http://php.net/manual/en/language.types.boolean.php Link to comment https://forums.phpfreaks.com/topic/275713-help-with-boolean-variables-and-going-in-and-out-of-tags/#findComment-1418931 Share on other sites More sharing options...
AureliusR Posted March 16, 2013 Author Share Posted March 16, 2013 Oh, of course! How silly of me... so if I change the if statement to == and drop the single quotes around the true/false assignments, I should be in business? Link to comment https://forums.phpfreaks.com/topic/275713-help-with-boolean-variables-and-going-in-and-out-of-tags/#findComment-1418932 Share on other sites More sharing options...
Jessica Posted March 16, 2013 Share Posted March 16, 2013 Probably, I didn't look at anything besides that one single = before coming back here. Give it a shot, it can't hurt to try. Link to comment https://forums.phpfreaks.com/topic/275713-help-with-boolean-variables-and-going-in-and-out-of-tags/#findComment-1418933 Share on other sites More sharing options...
AureliusR Posted March 16, 2013 Author Share Posted March 16, 2013 Jessica, you get an A+ I feel stupid now, lol. I should have remembered that. Thanks a ton! Link to comment https://forums.phpfreaks.com/topic/275713-help-with-boolean-variables-and-going-in-and-out-of-tags/#findComment-1418934 Share on other sites More sharing options...
Jessica Posted March 16, 2013 Share Posted March 16, 2013 If the form field is in the form it will be posted and if its empty it will be an empty string '' not truly empty. So you need to use strlen or other validation besides empty on your form fields. Link to comment https://forums.phpfreaks.com/topic/275713-help-with-boolean-variables-and-going-in-and-out-of-tags/#findComment-1418935 Share on other sites More sharing options...
AureliusR Posted March 16, 2013 Author Share Posted March 16, 2013 Okay, I'll keep that in mind. At this point, though, empty() is working fine. How would I use strlen? Link to comment https://forums.phpfreaks.com/topic/275713-help-with-boolean-variables-and-going-in-and-out-of-tags/#findComment-1418937 Share on other sites More sharing options...
timothyarden Posted March 16, 2013 Share Posted March 16, 2013 strlen() just returns the length of a given stringyou could do if(strlen($string) < 1) Link to comment https://forums.phpfreaks.com/topic/275713-help-with-boolean-variables-and-going-in-and-out-of-tags/#findComment-1418947 Share on other sites More sharing options...
timothyarden Posted March 16, 2013 Share Posted March 16, 2013 Might also want to use character type validationhttp://php.net/manual/en/book.ctype.php Link to comment https://forums.phpfreaks.com/topic/275713-help-with-boolean-variables-and-going-in-and-out-of-tags/#findComment-1418948 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.