0
我正在嘗試創建一個表單,用戶可以檢查其禮品卡餘額。我們使用的公司有一個可用的API。我希望能夠創建一個表格,讓用戶輸入他們的姓名和禮品卡號碼,點擊提交,並返回他們的卡餘額。向API提交表單變量並打印結果
我創建了這個表單,但我不想將這個變量傳遞給api,並將xml結果解析爲一個網頁。
API網址:http://apps.card9.com/api/?cmd=balance&card=卡號 &鍵= 我的API密鑰
我創建了一個基本形式:
<form action="balance.php" method="post">
Name: <input type="text" name="fname" />
Card #: <input type="text" name="cardId" />
<input type="submit" value="submit" name="submit">
</form>
PHP腳本我使用,我跑過嘗試:
if(isset($_POST['cardId'])){
$userId = $_POST['cardId'];
$obj = simplexml_load_file('http://apps.card9.com/api/?cmd=balance&card=' . $cardId . '&key=**my api Key**');
}else{
// failed to load the xml
}
如果任何人都可以幫助或指出我正確的方向,我將不勝感激。
謝謝!
你的問題是什麼?你卡在哪裏?我只是看到一些破損的代碼。 – Halcyon
您可以從POST設置變量$ userId,然後在API請求中使用$ cardId。 – ben