Jump to content

Am I covering my bases against MYSQL injection?


danbee

Recommended Posts

I've got a html page that takes in parameters from the address and passes them to a PHP script which accesses a MYSQL database. I'm only allowing alphanumeric characters with the exception of these symbols:

?

&

=

%

/

-

.

:

 

 

The scrubbing script I use is this:

$str = preg_replace('/[^a-zA-Z0-9?&=%\-.:\/ ]/i', '', $str);

 

Also, there are some variables that are numbers, so I run this following script to make sure it's numeric:

return (preg_match ("/^(-){0,1}([0-9]+)(,[0-9][0-9][0-9])*([.][0-9]){0,1}([0-9]*)$/", $value) == 1);

 

Is there anything else I need to worry about?

 

Link to comment
Share on other sites

The main worry in SQL Injection is the "single quote". If the single quote is not escaped someone could do something like this:

 

' OR 1

 

Which would return all records, or they could get really creative and delete the entire table.

 

Any rate before entry into the database you should escape your data with www.php.net/mysql_real_escape_string  to escape proper characters that could potentially harm you.

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.