Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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