Jump to content

Recommended Posts

Hi,

 

Maybe it is a simple questions but I can't figure it out.  Is there a way to get all the data from $_POST assigned to another variable?  What I want to do is get the whole string from $_POST, assign it to $data and then assign it to specific variables.  I know that it is possible to assign to variables using form but it is not the point here:

 

$data = $_POST;
$var = explode("&", $data);
$v1 = $var[1];
$v2=$var[2];
$v3=$var[3];
$v4=$var[4];

 

Thx

Link to comment
https://forums.phpfreaks.com/topic/167025-how-to-get-all-the-data-using-post/
Share on other sites

The html:

 

<html>
<head>
    <title>Test</title>
</head>
<body>
    <form action="foo.php">
        <input type="text" name="my_form_variable" />
        <input type="submit" />
    </form>
</body>
</html>

 

foo.php:

<?php

print_r($_POST);

$my_form_variable = $_POST['my_form_variable'];

die($my_form_variable);

$_POST is an array not a string. Take a look at the manual.

 

Hi it was it.  Thx.  I now try to put the values into variables with this code.  However some of the variables that take more than one word with spaces are merged (I see the result in the database record) - how can I show them with spaces?

 

$query_string = "";
if ($_POST) {
  $kv = array();
  foreach ($_POST as $key => $value) {
    $kv[] = "$key=$value";
  }
  $query_string = implode("&", $kv);
}
else {
  $query_string = $_SERVER['QUERY_STRING'];
}
$data = $query_string;
$var = explode("&", $data);
$time = $var[1];
$address=$var[2];
$message=$var[3];
$num_left=$var[4];

I dont know what you are doing, but it's crazy.

 

I don't think you understand how to use POST and GET. Try reading a tutorial or something. http://www.tizag.com/phpT/postget.php

 

I dont understand why you are combining POST and GET variables into a query string, and then exploding that into an array.  A lot of unnecessary stuff going on there.

 

Hi

 

thx for help.  Yes I have read the tutorial mentioned.  I'm trying to get some data using LSL from Second Life.

 

       

time = "12:23";
        address = "here";
        message = "Love me or hate me";
        num_left = 12;
        url += time;
        url += address;
        url += message;
        url += "12";
        //url += (string)num_left;

        llHTTPRequest(url, [HTTP_METHOD, "POST"], "");

 

I got the url with the POST method that I want to process using PHP to update database.  I AM NOT USING FORMS.  Everything is fine except that the places where words come with spaces are merged in the case of message variable for example.

 

thx

I do tried the most obvious approach

 

       

time = "12:23";
        address = "here";
        message = "Love me or hate me";
        num_left = 12;
        url += "id" + id;
        url += "time=" + time;
        url += "&address=" + address;
        url += "&message=" + message;
        url += "&num_left=" + "12";
        llHTTPRequest(url, [HTTP_METHOD, "POST"], "");

 

and corresponding php code

 

$time=$_POST['time'];
$address=$_POST['address'];
$message=$_POST['message'];
$num_left=$_POST['num_left'];
$query = "INSERT INTO messages VALUES ('','$time','$address','$message','$num_left')";
mysql_query($query);

 

but what is entered into database is an empty record:(.  That's why I have decided to first get $_POST into a string variable and then explode it into separate variables - but then words with spaces are merged together:(

 

Thx

 

I think I see what you are saying.  What are the contents of $_POST?  Can you do a print_r($_POST) and show me?

 

Why not explode on ';'.  That will seperate each value, and then you can explode each value on '='.

 

Something like:

<?php
$data = array();

$parameters = explode(';', $input);

foreach ($parameters as $parameter)
{
    list ($key, $value) = explode('=', $parameter);
    
    $data[trim($key)] = trim($value);
}

I think I see what you are saying.  What are the contents of $_POST?  Can you do a print_r($_POST) and show me?

 

Why not explode on ';'.  That will seperate each value, and then you can explode each value on '='.

 

Something like:

<?php
$data = array();

$parameters = explode(';', $input);

foreach ($parameters as $parameter)
{
    list ($key, $value) = explode('=', $parameter);
    
    $data[trim($key)] = trim($value);
}

 

Contents of $_POST would be " http://myurl.com/update.php?time=12:23&address=here&message=Love me or hate me&num_left=12" - this is what I get inside Second Life

 

the code should look like:

 

       

time = "12:23";
        address = "here";
        message = "Love me or hate me";
        num_left = 12;
        url += "time=" + time;
        url += ";address=" + address;
        url += ";message=" + message;
        url += ";num_left=" + "12";

and on php side:

 

$data = array();
$parameters = explode(';', $input);
foreach ($parameters as $parameter)
{
list ($key, $value) = explode('=', $parameter);
$data[trim($key)] = trim($value);
}
$time = $var[1];
$address=$var[2];
$message=$var[3];
$num_left=$var[4];
$query = "INSERT INTO messages VALUES ('','$time','$address','$message','$num_left')";

 

thx

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.