Jump to content

Recommended Posts

Hey people, Ive been playing with a bit of script for a while now, but I cannot get the desired results.

 

Basically, I am trying to work out how many records in my database are of a certain type.

 

The text that I type to put into the database would read this...  12' Vinyl Single

 

I add my slashes and things, so that within phpMyAdmin it reads... 12\' Vinyl Single which is fine so far.

 

Im using this code snippet to search the records and to figure out how many match that type, but I get 0 results. Ive tried to also escape the backslash aswell by having \\\ (one to escape a backslash and the third to escape the apostrophe next), but still no luck.

 

$query = "select * from products where ProductType = '12\' Vinyl Single'";
$result = mysql_query($query); 		
$rows = mysql_num_rows($result);
$vinylsingle12 = $rows;

 

Its probably something stupid, but im pulling my hair out trying to figure it out.

 

If anyone could help me, it would be much appreciated.

Link to comment
https://forums.phpfreaks.com/topic/57770-solved-mysql-escaping-with-backslash/
Share on other sites

Ditto mysql_real_escape_string() usage.

 

But as far as your original snippet, you either needed to be using two backslashes (one to escape the backslash in the string in PHP, then it will be a single backslash when it reaches MySQL), or you could have used two single quotes together: "...ProductType='12'' Vinyl Single'".  To MySQL two single quotes together means to escape it into one.

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.