Aretai Posted July 22, 2009 Share Posted July 22, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/167025-how-to-get-all-the-data-using-post/ Share on other sites More sharing options...
Adam Posted July 22, 2009 Share Posted July 22, 2009 $_POST is an array not a string. Take a look at the manual. Quote Link to comment https://forums.phpfreaks.com/topic/167025-how-to-get-all-the-data-using-post/#findComment-880647 Share on other sites More sharing options...
flyhoney Posted July 22, 2009 Share Posted July 22, 2009 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); Quote Link to comment https://forums.phpfreaks.com/topic/167025-how-to-get-all-the-data-using-post/#findComment-880654 Share on other sites More sharing options...
Aretai Posted July 22, 2009 Author Share Posted July 22, 2009 $_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]; Quote Link to comment https://forums.phpfreaks.com/topic/167025-how-to-get-all-the-data-using-post/#findComment-880680 Share on other sites More sharing options...
ldougherty Posted July 22, 2009 Share Posted July 22, 2009 If the values for your variables have spaces in them make sure you call them with '' such as $mycar['$1'] rather than $mycar[$1] as only the first part of the value would be caught without the '' Quote Link to comment https://forums.phpfreaks.com/topic/167025-how-to-get-all-the-data-using-post/#findComment-880686 Share on other sites More sharing options...
flyhoney Posted July 22, 2009 Share Posted July 22, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/167025-how-to-get-all-the-data-using-post/#findComment-880688 Share on other sites More sharing options...
Aretai Posted July 22, 2009 Author Share Posted July 22, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/167025-how-to-get-all-the-data-using-post/#findComment-880741 Share on other sites More sharing options...
Aretai Posted July 22, 2009 Author Share Posted July 22, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/167025-how-to-get-all-the-data-using-post/#findComment-880750 Share on other sites More sharing options...
flyhoney Posted July 22, 2009 Share Posted July 22, 2009 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); } Quote Link to comment https://forums.phpfreaks.com/topic/167025-how-to-get-all-the-data-using-post/#findComment-880754 Share on other sites More sharing options...
Aretai Posted July 22, 2009 Author Share Posted July 22, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/167025-how-to-get-all-the-data-using-post/#findComment-880767 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.