wtfsmd Posted December 30, 2006 Share Posted December 30, 2006 I am making a script, the user submits the information into the form field then when they hit submit it makes a html file.I am a complete newb at PHP I'm trying to teach myself with some help from Google and places like here. :-\(i cut out alot of the code here so it is easier to read)[code]<?php$data = "Molten Core - $attunement";$attunement = $_POST['attunement'];$filename = "applicants/$char_name a lvl $char_level $char_class.html";$fp = fopen("$filename","a");fwrite($fp, $data);fclose($fp);[/code]$attunement is a check option box.I wanted to know how i could make a if else for $attunement, such as if the user did not check the box, when it got displayed it would show like Not Attuned. Right now when they select the check box it shows up fine, but when they don't it shows up blank. (or maybe there is a better way to do it)[code]if ($attunement == yes) { echo '$attunement';} else { echo '- No Onyxia attunement';}[/code]Here is the form field page [url=http://overdriveguild.com/apply.php]http://overdriveguild.com/apply.php[/url]Here is where you see the output [url=http://overdriveguild.com/applicants/]http://overdriveguild.com/applicants/[/url] Link to comment https://forums.phpfreaks.com/topic/32270-need-help-with-some-php-code/ Share on other sites More sharing options...
chronister Posted December 30, 2006 Share Posted December 30, 2006 This looks good to me, you simply want to get a response of some sort on attunement right?? If so, the below code should work, I only changed the ==yes part, if $attunement does not exist, the else portion will be parsed, if $attunement does exist, then the if($attunement) part will parseif ($attunement ) { echo '$attunement';} else { echo '- No Onyxia attunement';} Link to comment https://forums.phpfreaks.com/topic/32270-need-help-with-some-php-code/#findComment-149797 Share on other sites More sharing options...
wtfsmd Posted December 30, 2006 Author Share Posted December 30, 2006 okay here is my next problem, When i put the in between $data = "If/Else right here"; Then all it does will post the code into the html file and will not execute it. Link to comment https://forums.phpfreaks.com/topic/32270-need-help-with-some-php-code/#findComment-149800 Share on other sites More sharing options...
play_ Posted December 30, 2006 Share Posted December 30, 2006 So you want to check if a checkbox is blank or not? Link to comment https://forums.phpfreaks.com/topic/32270-need-help-with-some-php-code/#findComment-149801 Share on other sites More sharing options...
wtfsmd Posted December 30, 2006 Author Share Posted December 30, 2006 basically yes, i know if it is blank when there is no information, but i would like it to tell me or whoever views it that No they did not check it. Link to comment https://forums.phpfreaks.com/topic/32270-need-help-with-some-php-code/#findComment-149802 Share on other sites More sharing options...
play_ Posted December 30, 2006 Share Posted December 30, 2006 [code]<form action="<? $_SERVER['PHP_SELF'] ?>" method="post"><input type="checkbox" name="cb" value="Testing" /><input type="submit" name="submit" /></form><?if (isset($_POST['submit'])) { @ $cb = $_POST['cb']; if(isset($cb)) { echo $cb; } else { echo 'You must check the box'; }}?>[/code] Link to comment https://forums.phpfreaks.com/topic/32270-need-help-with-some-php-code/#findComment-149804 Share on other sites More sharing options...
wtfsmd Posted December 30, 2006 Author Share Posted December 30, 2006 For them to check the box is an option I don't care if they do or do not check the box, its there for me to know if they have there attunement or not. Link to comment https://forums.phpfreaks.com/topic/32270-need-help-with-some-php-code/#findComment-149806 Share on other sites More sharing options...
chronister Posted December 30, 2006 Share Posted December 30, 2006 You cannot specify an if/else statement or any other function inside a variable.$data="if(blah blah){do this}"; will be interpreted as a string and as you said it has.You have to place your if/else statement in the spot where you are echoing the $data variable.[code]if(!$data){echo 'Nothing Selected'}else{echo $data;};[/code]The highlighted spot in the screenshot is where you will need to put the if/else code Side Note: Your Today's Date field in your form is not necessary, as you can use the date("Y-m-d"); to produce a date in the format of 2006-30-12 and make one less item the user has to input, and one less item you have to process.[attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/32270-need-help-with-some-php-code/#findComment-149895 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.