0

ok so what i am trying to do is loop through the POST data to create an array of the data to be used later. this is what i have but when i use is_array it returns not an array. i swear it was working at one point but now im not so sure.

$insertDB = array("");
		foreach($_POST as $key => &$value){
			$insertDB .= "$key => $value, ";
		}

so in the end i have array("$key" => "$value", "$key" => "$value", "$key" => "$value")

thanks in advance

Edited by itisnot_me: n/a

2
Contributors
6
Replies
7
Views
6 Years
Discussion Span
Last Post by itisnot_me
0

A few things. First you can accomplish what you are trying to do with

$insertDB = $_POST

. Second you don't need

$insertDB =  array("");

. Third you are using . = which is the string concatination assignment operator. You are looking for assignment like

$insertDB[$key] = $value;

. I hope this helps!

0

I was playing around with what you said but i couldnt get it to work within my script. so how are you really saying to do it?

the reason i have it that way is that i have it go into a function where it breaks apart the array into the way it needs be so i can run it into a query.

this is my set up

getPost(){
$insertDB = array("");
		foreach($_POST as $key => &$value){
			$insertDB .= "$key => $value, ";
		}
}
//within the query function. insertDB gets changed to $changes
//string up changes
$values = mysql_real_escape_string("");
            foreach ($changes as $key => $value)
            {
                $values .= $key."='{$value}', ";
            }
0

ok so i was taking a look at the manual you sent me to and i believe that i have a better understanding with the array brackets. and i am able to make array's but i have one problem. within the array it is creating brackets around the key like:

Array{
[tommy] => 12,
[bob] => 13
}
instead of like:
Array{
tommy => 12,
bob => 13
}

i do use the global keyword it is just that i didnt put it up there. also i dont want to do it within the function incase i need to do some custom stuff that needs or changes any values within the array before sending it to the DB function

0

The brackets you are seeing from the print_r output are just to indicate that those strings are keys. You can pass the $_POST array into your function and anything you do to it in the function won't affect it outside the function.

0

Cool thanks. ive learned alot and was able to apply the correct way to my code and coding techniques. After i applied it i had to do come cleaning up. After that it worked like a charm.

thanks alot for your help.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.