Jump to content

Website broken after PHP4 to PHP5 upgrade


dmort59

Recommended Posts

I get an error when i try to submit/insert data into the database, after upgrading PHP from 4.47 to 5.9

The following error:  catchable fatal error object of class std class could not be converted to string: on the line that reads

( $values .= (!empty($values)?",":"") . "'$val'"; )

 

Code:

// Insert data with an array

function xsql_array_insert($table, $array, $errno)

{

reset($array);

while(list($key, $val) = each($array))

{

$fields .= (!empty($fields)?",":"") . $key;

$values .= (!empty($values)?",":"") . "'$val'";

}

 

$query  = "INSERT INTO $table ($fields) VALUES ($values)";

debug($query);

 

$result = xsql_query($query, $errno);

return $result;

}

 

I would appreciate any help. Thanks

 

Hmm interesting. I don't see you ever set either $fields or $values to an empty string (which you need to do when you use the combo assignment/concatenate operator, if you don't want to generate an undefined variable notice) But i just tried a similar code, and it worked

//$fields = ""; works with these two lines commented or uncommented 
//$values = "d"; when uncommented, generates undefined variable notice
$key = "d";
$val = "dd";
$fields .= (!empty($fields)?",":"") . $key;
      $values .= (!empty($values)?",":"") . "'$val'";
  
  echo $fields. "<br />";
  echo $values."<br />";

Sorry, new PHP vers is 5.2.9.

I have seen some posts on this error in PHP 5.2xxx. I am a beginner, and by necessity trying to fix my site.  Without the 'while' portion in your response code, it returns of course ,"d" and "dd". I am not sure what difference the 'list' term in while(list  or the  '.' do in the statement. This code works in PHP 4.7.

How do I change the 'while' loop to loop through the array?

 

Thanks,  Dennis

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.