Jump to content
Larry Ullman's Book Forums

Chapter 11 Question 'quote'


Recommended Posts

Hello

I wrote out  script 11.1 in chapter 11 and the form seems to be working with one exception.

I can't get an error to show up when no quote is submitted.

here is the code with the conditions:

 

 if (!empty($_POST['quote']) && ($_POST['quote'] != 'Enter your quotation here.') ) {

 

 

}else{ //failed to enter a quotation
            print '<p style="color:red;"> Please enter a quotation!</p>';
            }
 
This is not working, I get no error message for submitting nothing, in fact, the 'Enter your quotation here' is recorded in the quotes.txt.
 
 
BTW , The condition below is working, I tested the other else statement:
 
 
 
else {//could not open file
                print '<p style="color: red;">Your quotation could not be stored due to a system error.</p>';
            
            }
when I moved the quotes.txt file to another directory, I did get the above error message.
 
Did I miss something?
Thanks
FYI I really love this book and can't wait to get to your OOP book.

 

Link to comment
Share on other sites

Thank you so much for the nice words! I really appreciate it. As for this issue, I'd start by doing 

print_r($_POST) 

to see what values exist. If you have an extra space or different character in the preset value of "quote", that conditional will be true. 

Link to comment
Share on other sites

 Share

×
×
  • Create New...