In pset7, I have two templates per controller (quote.php, buy.php, sell.php). The first controller is for the form (POST) and the second is for display (GET). When invalid data is entered, ex. invalid symbol is inputted, when users don't have sufficient funds, etc. (anything that requires an apology), I get two C$50 Finance headers, the bottom one says

Sorry! blah blah...

In the listed controllers, my code looks like this



Does anybody know how to fix this?

1 Answer 1


You appear to be doing it in a wrong way. quote.php, sell.php, buy.php, etc are the controllers themselves. You probably should receive input using the forms, do all the work you need (e.g., validating input, querying the database, etc) in the controllers and deliver the results to the views to be be rendered (if needed) or maybe redirect to another page.

What the function named render() basically does is that it takes in some arguments (e.g., the title of the page and the variables you want in scope) and simply requires the header, the template in question and the footer -- that is, it copies and pastes their contents in place. That's why if you called render more than once, you may get more than one header and one footer.

Now, how's render() called more than once in your code? Well, apparently, if the condition is false, then the else block is interpreted and it gets called once. If the next time the condition is true, the if block is interpreted and it gets called again.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .