我正在尝试使用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