<?php
// configuration
require("../includes/config.php");
if ($_SERVER["REQUEST_METHOD"] == "GET")
{
// else render form
render("quote_form.php", ["title" => "Quote"]);
}
// else if user reached page via POST (as by submitting a form via POST)
else if ($_SERVER["REQUEST_METHOD"] == "POST")
{
if(empty($_POST["symbol"]))
apologize("Please enter the stock symbol.");
else
{
$stock = lookup($_POST["symbol"]);
if(!$stock)
apologize("Invalid symbol.");
else
render("quote_output.php", ["price" => number_format($stock["price"], 2, '.', ',')]);
}
}
?>
//quote_output.php
<p>Price:<?=htmlspecialchars($message)?></p>
-
So if we're reading this correctly, quote_output.php is contained in a separate file that is so-named, and consists solely of the line <p>Price:<?=htmlspecialchars($message)?></p> ?– rongaJun 26, 2016 at 13:38
-
Yes.Just like apology.php.– Rahul AgrawalJun 26, 2016 at 18:43
1 Answer
Assuming you have the necessary headers (which you don't show in the above code snippet) in your quote_output.php file, your problem is the fact that it contains an undefined variable $message, which was not passed in via your render function.
-
Could you be a little specific regarding those headers(i have just one line of code in quote_output)? apology.php did not contain anything.And i surmise $message is passed on by the render function itself. Jun 27, 2016 at 18:29
-
Your browser will not recognize this as html 5 unless your code starts with the <!DOCTYPE html> header and ends with </html>. Also, what does $message contain? It's not defined in quote, nor do you pass it in via render, as you did with price.– rongaJun 28, 2016 at 1:50
-