Jump to content

Ignore ' in Query


Mko

Recommended Posts

I might be wrong....but i am not sure if you escape a single quote, the slash will get stored in database.

It just tells MySQL to not consider the single quote as a syntax

but again i might be wrong..

 

mysql> INSERT INTO `temp` (last_name) values ('sam\'shel');

Query OK, 1 row affected (0.00 sec)

 

mysql> SELECT * FROM temp\G

*************************** 1. row ***************************

        last_name: sam'shel

Link to comment
https://forums.phpfreaks.com/topic/259589-ignore-in-query/#findComment-1330606
Share on other sites

Use prepared statements.

 

Why exactly do you need quotes in your salt?

Well, the salts are randomly generated, and on occasion, may contain a '.

Then, the salts are combined with the hash that's generated elsewhere to produce the password. This password is referenced with the user input to determine if it's a match.

Link to comment
https://forums.phpfreaks.com/topic/259589-ignore-in-query/#findComment-1330607
Share on other sites

I might be wrong....but i am not sure if you escape a single quote, the slash will get stored in database.

It just tells MySQL to not consider the single quote as a syntax

but again i might be wrong..

 

mysql> INSERT INTO `temp` (last_name) values ('sam\'shel');

Query OK, 1 row affected (0.00 sec)

 

mysql> SELECT * FROM temp\G

*************************** 1. row ***************************

        last_name: sam'shel

 

Hmm, perhaps it does not then, I thought it did.

 

I've used only prepared statements for a long time. *shrug*

Link to comment
https://forums.phpfreaks.com/topic/259589-ignore-in-query/#findComment-1330608
Share on other sites

I might be wrong....but i am not sure if you escape a single quote, the slash will get stored in database.

It just tells MySQL to not consider the single quote as a syntax

but again i might be wrong..

 

mysql> INSERT INTO `temp` (last_name) values ('sam\'shel');

Query OK, 1 row affected (0.00 sec)

 

mysql> SELECT * FROM temp\G

*************************** 1. row ***************************

        last_name: sam'shel

 

Wohoo, it works!

Thanks a lot everyone, you've all been a tremendous help!

Link to comment
https://forums.phpfreaks.com/topic/259589-ignore-in-query/#findComment-1330609
Share on other sites

The same as you would for any data that may contain content that could foul the query: mysql_real_escape_string()

As a result, would the \ be inserted into the salt value in the database as well?

 

Yes.

 

Fail :P

 

That's the whole point of mysql_real_escape_string() - it escapes characters so they will be interpreted as literal characters in the query and not control characters (e.g. quotes around a value)

 

Example:

$value = "foo'bar";
$sql_value = mysql_real_escape_string($value);

$query = "INSERT INTO `table` (`field`) VALUES ('$sql_value')";
echo $query; //Output: INSERT INTO `table` (`field`) VALUES ('foo\'bar')

If that query is run the actual value inserted into the database will be foo'bar, without the backslash. It's not really any different than escaping quotemarks that are included in a quoted string

echo "<input type=\"text\" name=\"email\" />";

 

Link to comment
https://forums.phpfreaks.com/topic/259589-ignore-in-query/#findComment-1330611
Share on other sites

The same as you would for any data that may contain content that could foul the query: mysql_real_escape_string()

As a result, would the \ be inserted into the salt value in the database as well?

 

Yes.

 

Fail :P

 

Meh. :P

 

Like I said, it's been a long time since I've worked that way. I remember having to stripslashes data from a database at one point... must have been for some other reason.

Link to comment
https://forums.phpfreaks.com/topic/259589-ignore-in-query/#findComment-1330652
Share on other sites

Like I said, it's been a long time since I've worked that way. I remember having to stripslashes data from a database at one point... must have been for some other reason.

 

Probably using mysql_real_escape_string() on inserted values that were first run through magic quotes.

Link to comment
https://forums.phpfreaks.com/topic/259589-ignore-in-query/#findComment-1330776
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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