Background...
I inherited a nightmare. A backend php interface that was originally dev'd on a linux box . Told the site was migrating to a windows box w/ php 5. Redeveloped site on a widows box w/ php 5 ONLY to be informed that the site will now actually live on a linux box w/ php 4.3.2 .

Heres the prob

Most everything works now..
Except in passing an array as a form variable to a function that updates the database. Works on windows php 5 ... chokes on Linux PHP 4.3.2

here is the call to the function

<? // Aktionen des Editors
if ($action=='save') {
SaveRecord($Formfield, $Tablename); ?>

here is the function it is choking on. I bolded the choke points

function SaveRecord($Formfields, $Table) {
global $Fields;
reset($Fields);
if (is_array($Formfields[$Table])) {
$SQL_UPDATE = "UPDATE $Table SET ";
foreach($Fields as $Field) {
if (isset($Field['type']) && isset($Field['field'])) {
$Fieldtype = $Field['type'];
$Fieldname = $Field['field'];
if (!isset($Field['external']) || $Field['external'] != 'true' && array_key_exists($Fieldname, $Formfields[$Table])) {
$SQL_UPDATE .= " $Fieldname='" . str_ireplace("'", "''", $Formfields[$Table][$Fieldname]) . "', ";
}
}
}
$SQL_UPDATE = StripRight($SQL_UPDATE, ',');
$SQL_UPDATE .= " WHERE id=".$Formfields[$Table]['id'];
mysql_query($SQL_UPDATE) or die(mysql_error());
//return mysql_affected_rows();
}

//if (is_array($Formfields)) { echo'isarray';}else{echo 'notarray';}
// Appendixfelder speichern

reset($Formfields);
foreach($Formfields as $Source => $Tablefields) {
if (stripos($Source, '@') !== false) {
$AppendixSource = explode('@', $Source);
$AppendixTable = $AppendixSource[1];
} else {
$AppendixSource = $Source;
$AppendixTable = $Source;
}
$SQL_UPDATE = "\nUPDATE $AppendixTable SET ";
if (sizeof($AppendixSource) == 2) {
foreach($Tablefields as $Formfield => $Formvalue) {
if ($Formfield == 'id') {
$Index = $Formvalue;
} else {
$SQL_UPDATE.= "$Formfield='$Formvalue',";
}
}
$SQL_UPDATE = StripRight($SQL_UPDATE, ',');
$SQL_UPDATE.= "WHERE id=$Index";
mysql_query($SQL_UPDATE) or die(mysql_error());
//echo "\n$Update";
// echo "\n$AppendixSource[0] - $AppendixSource[1] - $Formfield[field]";
}
}
}

the prob is $formfields is not being recognized as an array on the linux 4.3.2
box
any clues would be greatly appreciated
thanks

    trying a var_dump on that variable just inside the function may lead to some clues about it.

      var_dump?
      thanks , wil do
      but i think it has something to do with how the php 4.3.2 is config'd
      since it has no prob working php 5 on our dev server

      notice my commented out flag
      //if (is_array($Formfields)) { echo'isarray';}else{echo 'notarray';}

      on the php 5 server I get "isarray' on the 4.3.2 server i get 'notarray'

      forgot to mention $formfields is a multi dimensional array.

      might that be the prob? with 4.3.2 linux

        interesting...........

        on php 5 windows-
        var_dump($Formfields);

        array(1) {
        ["content_events"]=>
        array(17) {
        ["id"]=>
        string(2) "57"
        ["_content_area"]=>
        string(1) "1"
        ["content_navi"]=>
        string(6) "I/2004"
        ["headline"]=>
        string(22) "2004, Friday, June 4th"
        ["leader"]=>
        string(0) ""
        ["date"]=>
        string(10) "2004-06-04"
        ["time_start"]=>
        string(7) "8:00 AM"
        ["time_end"]=>
        string(7) "5:00 PM"
        ["location"]=>
        string(0) ""
        ["address"]=>
        string(0) ""
        ["city"]=>
        string(0) ""
        ["state"]=>
        string(0) ""
        ["fee"]=>
        string(0) ""
        ["reg_nfo"]=>
        string(0) ""
        ["reg_ntk"]=>
        string(0) ""
        ["past_part"]=>
        string(0) ""
        ["pdf"]=>
        string(20) "G100SummitAgenda.pdf"

        on php 4.3.2 linux-
        var_dump($Formfields);

        string(0) ""

        but I already knew this...var_dump just confirmed it

        but why? can you not pass an array to a function in 4.3.2 linux??? Is it a php config setting?

          try passing it in by reference, like this...

          function SaveRecord(&$Formfields, $Table) {
          and then call it like normal
          SaveRecord($fields, $table);

            also forgot to mention im passing the array $Formfield from a form, although one might see that was obvious from the name of the array.

            i did a little more testing and found that the $Formfields var doesnt even make it to the function

            SaveRecord($Formfield, $Tablename);

            as an array. What I mean is it not even being passed to the page, from the form as an array

            the form variable/array $Formfield is constructed like this:

            <TR class='rowNormal' valign=top>
            <TD class='rowDark' nowrap>
            id
            </TD>
            <TD class='rowNormal' width='80%'>
            <input type=hidden name='Formfield[content_events][id]' value='56'>56
            </TD>
            </TR><input class=editString type=hidden name='Formfield[content_events][_content_area]' value='1'>
            <TR class='rowNormal' valign=top>
            <TD class='rowDark' nowrap>
            Content Navigation
            </TD>
            <TD class='rowNormal' width='80%'>
            <input class=editString type=text name='Formfield[content_events][content_navi]' value='II/2004'>
            </TD>
            </TR>
            <TR class='rowNormal' valign=top>
            <TD class='rowDark' nowrap>
            Headline
            </TD>
            <TD class='rowNormal' width='80%'>
            <input class=editString type=text name='Formfield[content_events][headline]' value='2004, Thursday, November 4 & Friday, November 5'>
            </TD>
            </TR>
            <TR class='rowNormal' valign=top>
            <TD class='rowDark' nowrap>
            Program Leader
            </TD>
            <TD class='rowNormal' width='80%'>
            <input class=editString type=text name='Formfield[content_events][leader]' value='yada yada'>
            </TD>
            </TR>

            can i pass an array ( multi dimensional array that is) thru a form in php 4.3.2?

            thanks for your insight

              yes, you should be able to pass an array, single or multidimensional from a form, but you might need to be calling it $_POST['Formfield'] rather than $Formfield if register_globals is turned off on this server.

                i am setting $Formfield like this.

                $Formfield = isset($POST['Formfield']) ? $POST['Formfield'] : array() ;

                and then passing it to the function.

                as $Formfield

                the register_globals is set like this (from phpinfo.php)

                register_globals On(local) Off(master)

                  seems like it should all be working okay.
                  id try to create a basic form with a few different arrays (single and multidimensional) and post them to a php script which will just var_dump $_POST to see what it receives.
                  then if it works as expected try passing some of those arrays into a function and see if they retain their values.

                    good idea
                    i did

                    using the same script outputted to var_dump()

                    i get this on the 4.3.2 linux box

                    &string(0) ""

                    i get this on the 5.0 windows box

                    array(1) {
                    ["content_events"]=>
                    array(17) {
                    ["id"]=>
                    string(2) "57"
                    ["_content_area"]=>
                    string(1) "1"
                    ["content_navi"]=>
                    string(6) "I/2004"
                    ["headline"]=>
                    string(22) "2004, Friday, June 4th"
                    ["leader"]=>
                    string(0) ""
                    ["date"]=>
                    string(10) "2004-06-04"
                    ["time_start"]=>
                    string(7) "8:00 AM"
                    ["time_end"]=>
                    string(7) "5:00 PM"
                    ["location"]=>
                    string(0) ""
                    ["address"]=>
                    string(0) ""
                    ["city"]=>
                    string(0) ""
                    ["state"]=>
                    string(0) ""
                    ["fee"]=>
                    string(0) ""
                    ["reg_nfo"]=>
                    string(0) ""
                    ["reg_ntk"]=>
                    string(0) ""
                    ["past_part"]=>
                    string(0) ""
                    ["pdf"]=>
                    string(20) "G100SummitAgenda.pdf"

                    its must be some setting in the php 4.3.2 build or something to do with it being a linux box....im just not up enough on administering the php config even if i had access to it, which i dont.

                    but thanks for you help.

                      Write a Reply...