Jump to content

Recommended Posts

Hello

 

I am still fairly new to the PDO / mysqli thing and I would really appreciate some help with escaping special characters from the below code.

$sth = ("SELECT * from table WHERE field1 = '$bob' and field2 != ''");

 foreach ($dbh->query($sth) as $row) {
  

 $who =  $row['field2']; 
  $why = $row['field1'];
 
$dbh1->query("UPDATE table SET who = '$who', date = '$row[DATE]', time = '$row[TIME]' WHERE field1 = '$why'")or die(mysqli_error($db));
}

I have tried using the prepared statement as well as the mysqli_real_escape_string but sees the code results as an object.

 

Any help or comments would be greatly appreciated.

 

 

Link to comment
https://forums.phpfreaks.com/topic/291984-pdomysqli-escape-characters-from-object/
Share on other sites

What api are you using? PDO or MySQLi? You can only use one or the other you can't use them both together.

 

If you are inserting data into the database you should be using prepared statements.

 

The PHP documentation has clear documentation for how to use prepared statements for both api's

  • PDO Prepared Statements 
  • MySQLi Prepared Statements
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.