Jump to content

Nightmares with quotes


WarKirby

Recommended Posts

Having an issue with a php script, I've narrowed the problem down to the fact that my quotesmart function is somehow putting two ' at the start of a string.

 

So I'm trying to add a little check in, so that it only adds ' quotes if the string doesn't already have them. How do I make this work though?

 

Specifically, I'm running two if checks, to see whether the first and then the last character, are equal to ' and only adding it if not. But trying to check if ($value[0] != "'") just doesn't really work. It messes up the code and everything after that is treated as a string.

 

so how can I do a comparison like this

 

Link to comment
Share on other sites

if (substr($value, 0, 1) == "'") { 
  //Do nothing, or add param to function to skip quote
} else { 
  //Add quote to beginning
}

 

Do  you mean something like this? But it would be helpful if you told us what the function was, and yeah, why it's adding them in the first place.

 

Link to comment
Share on other sites

The function puts single quotes around inputs and does some other stuff to prevent injection attacks.

 

The snippet you've posted is what I'm trying to use. Syntax highlighting in notepad++ shows everything after that line being treated as a quoted string, though. Are you sure that will work ?

Link to comment
Share on other sites

I don't see a reason for the quotesmart function, mysql_real_escape_string() should suffice for any data escaping.

 

Then just put the quotes in manually for the SQL queries, will save on the amount of code you write (the quotes i garuntee wil take less space than entire functions, and its quicker).

 

-CB-

Link to comment
Share on other sites

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.