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 Quote 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 />"; Quote 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 Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.