getdata.html
file must be a php file. Rename it to getdata.php
PHP Post script not working
-
15-10-2022 - |
Question
So I am trying to make a simple webpage that takes a users name and desired ticker on one page and fetch data on the second page as part of a school project. For some reason, the POST method is not working when I am trying to pass data. Any help with this would be great. Thanks!
form.php
<html>
<body>
<form action="getdata.php" method="post">
Name: <input type="text" name="name">
Ticker: <input type="text" name="ticker">
<input type="submit">
</form>
</body>
</html>
getdata.html
<html>
<body>
Hello <?php echo $_POST['name']; ?>!<br>
Your ticker is
<?php
echo $_POST["ticker"];
$endpoint = "http://query.yahooapis.com/v1/public/yql";
$ticker = "'".$_POST["ticker"]."'";
$query = urlencode("env 'store://datatables.org/alltableswithkeys';select * from yahoo.finance.quotes where symbol in (".$ticker.")");
$ch = curl_init($endpoint.'?q='.$query. '&format=json');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
if (curl_error($ch)){
die(curl_error($ch));
}
curl_close($ch);
echo'<pre>';
$result = json_decode($result);
$symbol = $result->query->results->quote->symbol;
print_r($symbol);
?>
</body>
</html>
Solution
OTHER TIPS
You are calling a PHP page in action, but you action page "getdata" not php, try it after rename it getdata.html to getdata.php
You should change the extension of file getdata
to get the data ticker
from form.php
.
Use,
getdata.php
Instead of
getdata.html
first change getdata.html to getdata.php and in your php code is better use isset() function
be successfull
Change getdata.html
to getdata.php
(Also in the <form>
tag).
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow