0

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(); ?>
Data46
  • 31
  • 8
  • whats the db field type. 2 i think you want curl() but the question is not very clear –  Jan 06 '14 at 02:37
  • It's possible the DB field is set to varchar(512) which will cut off any chars over 512 and not save them. Change it to be a TEXT field type for long strings – dennismonsewicz Jan 06 '14 at 02:40
  • type=text, collation=latin1_swedish_ci – Data46 Jan 06 '14 at 02:46
  • Please, read what SQL injection is and stop using `mysql_` functions. – Kermit Jan 06 '14 at 03:15
  • @FreshPrinceOfSO - I'll use: $stmt = $dbh->prepare($query); once i get it working, it's just a test script - thanks for the valid point though. – Data46 Jan 06 '14 at 03:19

2 Answers2

0

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.

Nick Coons
  • 3,682
  • 1
  • 19
  • 21
  • Thank Nick, i'll try curl if i can get past 512 char limitation. Added pic of table config, if that helps in OP. – Data46 Jan 06 '14 at 02:50
0

Answer 1 Yes, max length of url has restriction. See more: What is the maximum possible length of a query string?

Answer 2 You can send your string like simple varible ($_POST). Check only settings for max vals of inputing/exectuting in php.ini.

Community
  • 1
  • 1
voodoo417
  • 11,861
  • 3
  • 36
  • 40
  • Thanks for the link; 2nd answer states "A URL is like an address to something, it's not the best way to pass information to something. A POST request is much more appropriate, if it can be used." So is a POST request different to a 'normal url'? Forgive the silly question, i can just about spell PHP. – Data46 Jan 06 '14 at 03:28