Jump to content

TRIM quotation marks


cliftonbazaar

Recommended Posts

I have the following code

$sql_statement = "SELECT * FROM toon WHERE ally_code = '".$user['ally_code']."' and name = '".$toons_array[$i][1]."' LIMIT 1";

Which works except if the persons 'name' has quotation marks in it, for example the name of Adam "Danger" Smith doesn't match with Adam Danger Smith.

 

My best attempt was

$sql_statement = "SELECT * FROM toon WHERE ally_code = '".$user['ally_code']."' and trim( both '"' from name) = '".$toons_array[$i][1]."' LIMIT 1";

Any suggestions please?

Link to comment
Share on other sites

Then wouldn't stripping the quotation marks also stop the injection attack?

 

 

no. sql can be injected that contains no quotes, for which your proposed method won't protect against.

 

do what was stated and use prepared queries, with place-holders for the data values in the sql query statement, then provide the data values when the query gets executed. this will also greatly simplify your sql query statement, because the php variables, single quotes around the values. and the concatenation dots will be removed.

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.