Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

PHP 

Single quotes being escaped

So I'm inserting content into a mysqli database, but when I do, it's escaping single quotes, even though nothing in my code is making it do that. Does PDO do this automatically or something? How can I fix it? It needs to be echoed out to a page.

Edit: to commentate for this, I'm using stripslashes(), but any explanation why it's doing this in the first place?
Account Cracking | Website Pentesting

(Mar 31, 2014 09:43 PM)michael1026 Wrote:  So I'm inserting content into a mysqli database, but when I do, it's escaping single quotes, even though nothing in my code is making it do that. Does PDO do this automatically or something? How can I fix it? It needs to be echoed out to a page.

Edit: to commentate for this, I'm using stripslashes(), but any explanation why it's doing this in the first place?

Try to insert content without using stripslashes().
(Mar 31, 2014 10:02 PM)Yani Wrote:  Wait, are you using mysqli or PDO?
Also, showing your code would actually be better.
PDO, sorry for the confusion. I don't have much code....

PHP Code

<?php 
$content 
= $_POST['topic_content'];
      
$stmt = $dbh->prepare("INSERT INTO posts (post_content) VALUES (:content)");
      
$stmt->bindParam(':content', $content);
      
$stmt->execute(); 

I think it may be my host that's doing it automatically.


(Mar 31, 2014 09:56 PM)La Manifesto Wrote:  Try to insert content without using stripslashes().

I have. I used stripslashes after I found out that it was doing this to remove them.
Account Cracking | Website Pentesting

(Mar 31, 2014 10:11 PM)michael1026 Wrote:  PDO, sorry for the confusion. I don't have much code....

PHP Code

<?php 
$content 
= $_POST['topic_content'];
      
$stmt = $dbh->prepare("INSERT INTO posts (post_content) VALUES (:content)");
      
$stmt->bindParam(':content', $content);
      
$stmt->execute(); 

I think it may be my host that's doing it automatically.



I have. I used stripslashes after I found out that it was doing this to remove them.

You could always try addslashes(), it might work.
(Mar 31, 2014 10:13 PM)La Manifesto Wrote:  You could always try addslashes(), it might work.

Well, right now stripslashes is working. I was just curious why this was happening in the first place. I'm just going to assume that it's the host that does it automatically.
Account Cracking | Website Pentesting

(Mar 31, 2014 10:24 PM)michael1026 Wrote:  Well, right now stripslashes is working. I was just curious why this was happening in the first place. I'm just going to assume that it's the host that does it automatically.

Oh I wasn't clear on that. I assume it doesn't work because PDO automatically removes stuff like that when you bind them.
Sounds like you have magic_quotes turned on.

http://www.php.net/manual/en/security.ma...s.what.php
http://en.wikipedia.org/wiki/Magic_quotes


Possibly Related Threads...
Thread / Author Replies Views Last Post
[PHP] by deadsh0tFeb 5, 2018 01:26 PM 7 254 Feb 5, 2018 01:26 PM
Last Post: Charger
[PHP] by Sir-TeabagNov 19, 2017 08:03 PM 5 208 Nov 19, 2017 08:03 PM
Last Post: Charger
[PHP] by DJSanderrrMar 2, 2016 06:20 PM 21 358 Mar 2, 2016 06:20 PM
Last Post: Terebic