Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading Array sent via Post 2

Status
Not open for further replies.

likelylad

IS-IT--Management
Jul 4, 2002
388
GB
I don't know whether this is the right forum for this but I think the issue is with PHP.

I am trying to send array information via post into a PHP page using the following snippet of code

Code:
function changecolumn1() {

var test=Sortable.serialize("<?php echo $tabname.'Column1' ?>")
new Ajax.Request("updatecolumn1.php?thedesc=<?php echo $tabname.'Column1' ?>&rowdata="+test, {method: 'post',parameters: { data: Sortable.serialize('<?php echo $tabname.'Column1') }})

}
I am using the code for drag and drop using scriptaculous.
In my php page I can access the variable "thedesc".

I am unable to see the array information in "rowdata" or "data". I know that both these contain the same information but I was trying different ways to see the information.

I am confident that there is information in the array as if I add Alert(test) then there is information there.

I would be extremely grateful for any help received as I am really struck on this one
 
What are you doing with the data in PHP? Maybe you could post the relevant code. You're not dependind on register_globals or something like that, are you?

The easiest thing to check is to do a var_dump($_POST) and var_dump($_GET) in your PHP script? If request is going through, then you should see your data in there - or the "rowdata" and/or "data" indices should at least be set.

Another thing to try would be to use FireBug or something similar to check that the AJAX request is going through and has all the expected data.
 
This is what I am using on the PHP side
Code:
// MySQL Connection String
$column=$_GET[thedesc];
parse_str('data');
 


for ($i = 0; $i < count($callcentreColumn1); $i++) {   
    // The following line is for the MySQL query.   
mysqli_query($db,"INSERT INTO [i]tablename[/i] (Tabname,ColumnNumber) VALUES('$column','$callcentreColumn1[$i]')");   
}
 
Installed Firebug and this is what I see in the Post Statement

data=callcentreColumn1%5B%5D%3D6%26callcentreColumn1%5B%5D%3D5
 
interesting you say your are using post but your looking at $_GET, try using $_POST to see if it's there
 
What is the purpose of this line?
Code:
parse_str('data');
If it's intended to get data out of the 'data' POST field, that's not how it works. The parse_str() function takes a query string, i.e. something in the form "data=foo&bar=baz", and parses that into variables in the current scope. You've just passed it the single literal string 'data', which will do nothing.

Instead, as ingresman mentioned, you want to directly reference $_POST['data']. The $_POST array will be automatically populated with subscripts for each one of your POST variables, so something like parse_str() is unnecessary.
 
Thanks very much for your help. It has helped me to solve one part of my problem. I have done a seperate post for the second part of this problem.

My code now looks like the following and it does as I expect it to.
Code:
// MySQL Connection String
$column=$_GET[thedesc];
parse_str($_POST['data']);
 
for ($i = 0; $i < count($callcentreColumn1); $i++) {   
    // The following line is for the MySQL query.   
mysqli_query($db,"INSERT INTO tablename (Tabname,ColumnNumber) VALUES('$column','$callcentreColumn1[$i]')");   
}

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top