0

I've tried to pass the array from quote.php to a template result_symbol.php using this code.

    <?php

    // configuration
    require("../includes/config.php");

   // if user reached page via GET (as by clicking a link or via redirect)
   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")
{
    // TODO
if(empty($_POST["symbol"]))
{
    apologize("Bad symbol.");
}
$quote = [];
$stock = lookup($_POST["symbol"]);
$quote[] = [
"symbol" => $stock["symbol"],
"name" => $stock["name"],
"price" => $stock["price"]
];
render("result_symbol.php", ["quote" => $quote, "title" => "Quote"]);

}

?>

But that gives me an error when using this template code:

    <form action="../public/quote.php" method="post">
<fieldset>
    <div class="form-group">
        <?php
        print("Symbol : ".$quote["symbol"]."\n");
    print "\n";
    print("Name   : ".$quote["name"])."\n";
    print "\n";
    print("Price  : ");
    print number_format($quote["price"], 4);
    ?>
    </div>
    </fieldset>

or Quote other or Log in

But i got an error:undefined symbol What am i doing wrong? However, if i call lookup from inside the template, it works.

0

I've used the print_r function, it showed me the array was doubly indexed (don't know why, but...), so when i referenced with 2 indexes it worked.

1

You must log in to answer this question.

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