我正在嘗試使用PHP/POST/etc來幫助我在當天的Webdev工作。從教程等,我已經看到在線,這應該工作。但是,當我點擊提交時,頁面被重定向到bagelBack.php
,但是有一個空白頁面,並且未提交推文。我在我自己的機器上使用XAMPP Apache。 (在HTML頁面上有jQuery,如果有幫助的話)Form will not post
編輯:它在php($connection->request
等)的第40行上失敗。 var_dump
的工作,但echo
沒有。我對這一切都很陌生。爲什麼這不會引發錯誤?
HTML:
<form id="bagelForm" action="bagelBack.php" method="POST">
<label for="twitterName">Twitter Name: </label><input type="text" id="twitterName" name="twitterName"/><br />
<label for="bagelType">Bagel Type: </label><input type="text" id="bagelType" name="bagelType"/><br />
<input type="submit" />
</form>
PHP(主要來自here):
<?php
/**
* bagelBack.php
* Example of posting a tweet with OAuth
* Latest copy of this code:
* http://140dev.com/twitter-api-programming-tutorials/hello-twitter-oauth-php/
* @author Adam Green <[email protected]>
* @license GNU Public License
*/
$name = "@".$_POST['twitterName'];
$type = $_POST['bagelType'];
$tweet_text = $name.", your ".$type." bagel has finished toasting!";
$result = post_tweet($tweet_text);
echo "Response code: " . $result . "\n";
function post_tweet($tweet_text) {
// Use Matt Harris' OAuth library to make the connection
// This lives at: https://github.com/themattharris/tmhOAuth
require_once('tmhOAuth.php');
// Set the authorization values
// In keeping with the OAuth tradition of maximum confusion,
// the names of some of these values are different from the Twitter Dev interface
// user_token is called Access Token on the Dev site
// user_secret is called Access Token Secret on the Dev site
// The values here have asterisks to hide the true contents
// You need to use the actual values from Twitter
$connection = new tmhOAuth(array(
'consumer_key' => '[redacted]',
'consumer_secret' => '[redacted]',
'user_token' => '[redacted]',
'user_secret' => '[redacted]'
));
// Make the API call
$connection->request('POST',
$connection->url('1/statuses/update'),
array('status' => $tweet_text));
return $connection->response['code'];
}
?>
您是否嘗試過使用var_dump($ name)變量來查看是否有任何內容?還有,你是否試圖刪除post_tweet函數,看看你是否可以讓帖子進入下一頁?文件名是否正確? – chadpeppers
你有沒有試過'echo $ name;'和'echo $ type;'?你看到了什麼? – robonerd
這些變量都很好。問題出現在'post_tweet'中,爲什麼它會像沒有顯示錯誤那樣死去? – SomeKittens