Вопрос

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> 
Это было полезно?

Решение

getdata.html file must be a php file. Rename it to getdata.php

Другие советы

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).

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top