【问题标题】:Form won't post表格不会发布
【发布时间】:2012-06-12 02:18:21
【问题描述】:

我正在尝试使用 PHP/POST/etc 来帮助我完成作为 Web 开发人员的日常工作。从我在网上看到的教程等,这应该可以工作。但是,当我点击提交时,页面被重定向到bagelBack.php,但是有一个空白页面,并且没有提交推文。我在自己的机器上,使用 XAMPP Apache。 (HTML 页面上有 jQuery,如果有帮助的话)

编辑:它在 php 的第 40 行失败($connection->request 等)。 var_dumps 有效,但 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 <140dev@gmail.com>
* @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 功能,看看你是否可以让帖子转到下一页?文件名正确吗?
  • 你试过echo $name;echo $type;吗?你看到了什么?
  • 变量发布正常。问题出在post_tweet 为什么会这样死掉而不显示错误?
  • 您的错误可能没有显示或其他内容。您的 tmhOAuth.php 与 bagelBack.php 的位置是否相同?
  • PHP error_reporting 设置为 E_ALL & ~E_STRICT。是的,它在同一个目录中。

标签: php html post twitter twitter-oauth


【解决方案1】:

我不久前在遇到同样的问题时写了这篇文章:

http://www.highonphp.com/php-fastcgi-post-requests-failing

这与 webhost 已安装的 fcgi 与 cgi SAPI 有关。

【讨论】:

  • 我正在发布到我的 PHP 中。问题在于 post_tweet 函数。
猜你喜欢
  • 2015-01-11
  • 2019-06-26
  • 2012-01-19
  • 1970-01-01
  • 2011-01-15
  • 2017-08-25
  • 1970-01-01
  • 2021-03-01
  • 2015-01-18
相关资源
最近更新 更多