Comptons_Eazy_E Posted December 27, 2009 Share Posted December 27, 2009 <?php $errormsg = 'You left a field blank! Go back and fill it in.'; if(!empty($_POST['fname'])) { echo $errormsg; return 1; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/186399-why-wont-this-code-work/ Share on other sites More sharing options...
eazyefolife Posted December 27, 2009 Share Posted December 27, 2009 Sorry for double post, I changed my email for my account and i typed in the wrong email, so i had to create another . Quote Link to comment https://forums.phpfreaks.com/topic/186399-why-wont-this-code-work/#findComment-984331 Share on other sites More sharing options...
teamatomic Posted December 27, 2009 Share Posted December 27, 2009 get rid of the return, you dont need it there. Read the manual on return. As you are using it it is stopping your script. Quote Link to comment https://forums.phpfreaks.com/topic/186399-why-wont-this-code-work/#findComment-984333 Share on other sites More sharing options...
eazyefolife Posted December 27, 2009 Share Posted December 27, 2009 Even when i remove it, it still doesnt work. Quote Link to comment https://forums.phpfreaks.com/topic/186399-why-wont-this-code-work/#findComment-984334 Share on other sites More sharing options...
defeated Posted December 27, 2009 Share Posted December 27, 2009 I suspect the problem is having if(!empty(..... insead of if(empty(..... Â ! denotes not so "if (!empty" reads "if not empty", but that would mean that the error shows if the field is filled in rather than blank. Quote Link to comment https://forums.phpfreaks.com/topic/186399-why-wont-this-code-work/#findComment-984336 Share on other sites More sharing options...
eazyefolife Posted December 27, 2009 Share Posted December 27, 2009 I suspect the problem is having if(!empty(..... insead of if(empty(..... Â ! denotes not so "if (!empty" reads "if not empty", but that would mean that the error shows if the field is filled in rather than blank. Â Still no luck (New code) Â $errormsg = 'You left a field blank! Go back and fill it in.'; if(empty($_POST['fname'])) { echo $errormsg; } Quote Link to comment https://forums.phpfreaks.com/topic/186399-why-wont-this-code-work/#findComment-984337 Share on other sites More sharing options...
defeated Posted December 27, 2009 Share Posted December 27, 2009 I can't see anything wrong with that code at all. Try doing this... $errormsg = 'You left a field blank! Go back and fill it in.'; echo "<h2>fname: ".$_POST['fname']."</h2>"; if(empty($_POST['fname'])) { Â echo $errormsg; } Â If the data you put into the fname field does not come up in a big F off h2 heading, then your problem is with your post. Â Ooops, forgot to say that you have to put something into the fname field to test it. Â Quote Link to comment https://forums.phpfreaks.com/topic/186399-why-wont-this-code-work/#findComment-984340 Share on other sites More sharing options...
eazyefolife Posted December 27, 2009 Share Posted December 27, 2009 I can't see anything wrong with that code at all. Try doing this... $errormsg = 'You left a field blank! Go back and fill it in.'; echo "<h2>fname: ".$_POST['fname']."</h2>"; if(empty($_POST['fname'])) { Â echo $errormsg; } Â If the data you put into the fname field does not come up in a big F off h2 heading, then your problem is with your post. Â Ooops, forgot to say that you have to put something into the fname field to test it. Â I know my fname works because it sends a email what the fname was. Quote Link to comment https://forums.phpfreaks.com/topic/186399-why-wont-this-code-work/#findComment-984343 Share on other sites More sharing options...
defeated Posted December 27, 2009 Share Posted December 27, 2009 You could also try $fname=$_POST['fname']; if($fname=="") {  echo $errormsg; }//end if else {  echo "String_post contained: ".$fname; }//end else  Then you can get rid of the else section if it works. Quote Link to comment https://forums.phpfreaks.com/topic/186399-why-wont-this-code-work/#findComment-984346 Share on other sites More sharing options...
eazyefolife Posted December 27, 2009 Share Posted December 27, 2009 You could also try $fname=$_POST['fname']; if($fname=="") {  echo $errormsg; }//end if else {  echo "String_post contained: ".$fname; }//end else  Then you can get rid of the else section if it works.  No luck, Like no message shows up =/ Quote Link to comment https://forums.phpfreaks.com/topic/186399-why-wont-this-code-work/#findComment-984349 Share on other sites More sharing options...
defeated Posted December 27, 2009 Share Posted December 27, 2009 ok, lets see the form code and all the code on the receiving page up to and including the bit we have been looking at. I'm off out to walk the dog for 5 mins and then I'll look at it. Quote Link to comment https://forums.phpfreaks.com/topic/186399-why-wont-this-code-work/#findComment-984350 Share on other sites More sharing options...
eazyefolife Posted December 27, 2009 Share Posted December 27, 2009 ok, lets see the form code and all the code on the receiving page up to and including the bit we have been looking at. I'm off out to walk the dog for 5 mins and then I'll look at it.  ok This is the code: <form action="unbanp.php" method="post">  <p>Ingame Name </p>  <p>  <input type="text" name="fname" />  </p>  <p>-------------------------------------------</p>  <p>Admin/Moderator That Banned you:</p>  <p>  <input type="text" name="aban" />  </p>  <p>-----------------------------------------</p>  <p>IP Address:</p>  <p>  <input type="text" name="ip" />   </p>  <p>(http://www.whatsmyip.org)</p>  <p>------------------------------------------------</p>  <p>Reason Given why you were banned</p>  <p>:  <textarea name="aban2" cols="50" rows="6"></textarea>  </p>  <p>------------------------------------------------------</p>  <p>Your Story</p>  <textarea name="aban3" cols="50" rows="6"></textarea>  <p>------------------------------------------------------------</p>  <p>Additional Details?</p>  <p><textarea name="aban4" cols="50" rows="6"></textarea></p>  <p>----------------------------------------------------------  <p>Email Address (So we can contact if you are unbanned)</p>  <p>   <input name="email" type="text" value="" size="50" maxlength="1" />  </p>   <input type="submit" />  </p> </form> Quote Link to comment https://forums.phpfreaks.com/topic/186399-why-wont-this-code-work/#findComment-984352 Share on other sites More sharing options...
defeated Posted December 27, 2009 Share Posted December 27, 2009 Need the code on unbanp.php too. Up to the bit we were looking at. Quote Link to comment https://forums.phpfreaks.com/topic/186399-why-wont-this-code-work/#findComment-984357 Share on other sites More sharing options...
eazyefolife Posted December 27, 2009 Share Posted December 27, 2009 Need the code on unbanp.php too. Up to the bit we were looking at.  ..... (design and shit up there) ..... ===============================================================================================================</ <?php $errormsg = 'You left a field blank! Go back and fill it in.'; $fname=$_POST['fname']; if($fname=="") {  echo $errormsg; }//end if else {  echo "String_post contained: ".$fname; } $ip=$_SERVER['REMOTE_ADDR']; $to = '[email protected]'; $subject = "Unban Request - " . $_POST['fname']; $from = '[email protected]'; $message = "Admin/Moderator That Banned - " . $_POST['aban'] . "\n\nIP Address - " . $_POST['ip'] . " | Tracked IP -" . $_SERVER['REMOTE_ADDR'] . "\n\nReason Given why player was banned - " . $_POST['aban2'] . "\n\nYour Story - " . $_POST['aban3'] . "\n\nAdditional Details - " . $_POST['aban4'] . "\n\nEmail Address - " . $_POST['email']; if(mail($to, $subject, $message, "From: $from"))  echo "Unban Request Sent."; else  echo "Unban Request couldnt be Sent."; ?> <p> Thank You For Submitting Your Unban Request! <p> </html> Quote Link to comment https://forums.phpfreaks.com/topic/186399-why-wont-this-code-work/#findComment-984360 Share on other sites More sharing options...
defeated Posted December 27, 2009 Share Posted December 27, 2009 It works for me! Try running unbanp.php through this syntax checker. http://www.meandeviation.com/tutorials/learnphp/php-syntax-check/ Quote Link to comment https://forums.phpfreaks.com/topic/186399-why-wont-this-code-work/#findComment-984361 Share on other sites More sharing options...
eazyefolife Posted December 27, 2009 Share Posted December 27, 2009 It works for me! Try running unbanp.php through this syntax checker. http://www.meandeviation.com/tutorials/learnphp/php-syntax-check/  No errors were found, but note this is just a syntax check - there may be other errors or problems that will only appear when you upload and run the PHP script.  Also note that this file was checked against PHP 4. There are slight syntax differences between versions.  If you are a beginner try the PHP tutorial on this site  Quote Link to comment https://forums.phpfreaks.com/topic/186399-why-wont-this-code-work/#findComment-984362 Share on other sites More sharing options...
defeated Posted December 27, 2009 Share Posted December 27, 2009 Sorry, I don't know what else to suggest. There is nothing wrong with the code. It should work. I'm too tired to think straight now anyway, so I'm off to my bed. If I think of anything I'll drop back in. Quote Link to comment https://forums.phpfreaks.com/topic/186399-why-wont-this-code-work/#findComment-984375 Share on other sites More sharing options...
eazyefolife Posted December 27, 2009 Share Posted December 27, 2009 Sorry, I don't know what else to suggest. There is nothing wrong with the code. It should work. I'm too tired to think straight now anyway, so I'm off to my bed. If I think of anything I'll drop back in.  Thanks for trying to help me! Quote Link to comment https://forums.phpfreaks.com/topic/186399-why-wont-this-code-work/#findComment-984388 Share on other sites More sharing options...
PFMaBiSmAd Posted December 27, 2009 Share Posted December 27, 2009 What exact output ARE you getting in your browser? Are you getting any of the output from this code at the end of the page - if(mail($to, $subject, $message, "From: $from"))  echo "Unban Request Sent."; else  echo "Unban Request couldnt be Sent."; ?> <p> Thank You For Submitting Your Unban Request! <p> </html>  And what does a "view source" of the page in your browser show? Quote Link to comment https://forums.phpfreaks.com/topic/186399-why-wont-this-code-work/#findComment-984389 Share on other sites More sharing options...
eazyefolife Posted December 27, 2009 Share Posted December 27, 2009 What exact output ARE you getting in your browser? Are you getting any of the output from this code at the end of the page - if(mail($to, $subject, $message, "From: $from"))  echo "Unban Request Sent."; else  echo "Unban Request couldnt be Sent."; ?> <p> Thank You For Submitting Your Unban Request! <p> </html>  And what does a "view source" of the page in your browser show?  I'm not trying to show that. It's supposed to be: "You left your Name Empty." Then thats it. It wont send the email Quote Link to comment https://forums.phpfreaks.com/topic/186399-why-wont-this-code-work/#findComment-984515 Share on other sites More sharing options...
PFMaBiSmAd Posted December 27, 2009 Share Posted December 27, 2009 I asked you three specific questions about what you are getting as output. We are not standing right next to you. If you aren't, can't, or won't communicate what you are doing and what results you are getting when you do it, no one can help you. Quote Link to comment https://forums.phpfreaks.com/topic/186399-why-wont-this-code-work/#findComment-984519 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.