dmort59 Posted November 19, 2009 Share Posted November 19, 2009 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 Link to comment https://forums.phpfreaks.com/topic/182103-website-broken-after-php4-to-php5-upgrade/ Share on other sites More sharing options...
mikesta707 Posted November 19, 2009 Share Posted November 19, 2009 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 />"; Link to comment https://forums.phpfreaks.com/topic/182103-website-broken-after-php4-to-php5-upgrade/#findComment-960661 Share on other sites More sharing options...
dmort59 Posted November 19, 2009 Author Share Posted November 19, 2009 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 Link to comment https://forums.phpfreaks.com/topic/182103-website-broken-after-php4-to-php5-upgrade/#findComment-960828 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.