dongxing5525 2014-01-06 02:36
浏览 8

如何将长字符串发布到PHP页面?

This question has two parts:

Part I - restriction?

I'm able to store data to my DB with this:

www.mysite.com/myscript.php?testdata=abc123

This works for a short string (eg 'abc123') and the page echos what was written to the DB; however, if the [testdata=] string is longer than 512 chars and i check the database, it shows a row has been added but it's blank and also my echo statement in the script doesn't display the input string.

N.B. I'm on a shared server and have emailed my host to see if it's a restriction.

Part II - best practice?

If i can get past the above hurdle, I want to use a string that's ~15k chars long created in a desktop app that concatenates the [testdata=] string from various parameters; what's the best way to send a long string in PHP POST?

Thanks in advance for your help, i'm not too savvy with PHP.

Edit: Table config: enter image description here

Edit2: Row anomaly with long string > 512 chars: enter image description here

Edit3: here's my PHP script, if it helps:

<?
include("connect.php");

$data = $_GET['testdata'];
$result = mysql_query("INSERT INTO test (testdata) VALUES ('$data')");

if ($result) // Check result
{
    echo $data;                 
}
else echo "Error ".$mysqli->error;

mysql_close(); ?>
  • 写回答

2条回答 默认 最新

  • dqdt45183 2014-01-06 02:40
    关注

    POST is definitely the method you want to use, and your best bet with that will be with cURL. Something like this should work:

    $ch = curl_init();
    
    curl_setopt( $ch, CURLOPT_URL,        "http://www.mysite.com/myscript.php" );
    curl_setopt( $ch, CURLOPT_POST,       TRUE );
    curl_setopt( $ch, CURLOPT_POSTFIELDS, $my_really_long_string );
    
    $data = curl_exec( $ch );
    

    You'll need to modify the above to include additional cURL options as per your environment, but something like this is what you'd be looking for.

    You'll want to make sure that your DB field is long enough to hold the really long string as well.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。