2014-02-23 126 views
1

所以我試圖做一個簡單的網頁,在一個頁面上使用用戶名和想要的代碼,並在第二頁上獲取數據作爲學校項目的一部分。出於某種原因,當我嘗試傳遞數據時,POST方法不起作用。任何幫助,這將是偉大的。謝謝!PHP Post script does not working

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> 
+2

將getdata.html更改爲getdata.php –

+1

'不工作' - 簡潔,準確且完全無用作爲診斷援助。描述應該發生什麼以及實際發生了什麼。包含任何錯誤消息 - 並確保你已經檢查了你的服務器錯誤日誌。 – 2014-02-23 18:42:24

+0

是getdata.html嗎?因爲你的表單的行爲是getdata.php –

回答

2

​​文件必須是PHP文件。 (在<form>標籤也),其重命名爲getdata.php

0

變化​​到getdata.php

1

要調用的行動PHP頁面,但是你的動作頁「的GetData」不是PHP,嘗試後,將其重命名getdata.html來訪問getdata.php

1

你應該改變文件getdata的擴展來獲得數據tickerform.php

使用,

getdata.php 

而不是

getdata.html 
1

第一個變化getdata.html來訪問getdata.php和你的PHP代碼是更好的使用isset()函數功能

是全成