Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

What's the right way to prevent SQL injection in PHP scripts?

user-image
Question added by Khadijah Shtayat , Technical Lead , Opensooq
Date Posted: 2013/09/08
Fadi Alkhateeb
by Fadi Alkhateeb , Senior Front End Developer , NexTwo

Use prepared statements and parameterized queries (PDO & Mysqli).

PDO : http://php.net/manual/en/book.pdo.php

MYsqli : http://php.net/manual/en/book.mysqli.php

 

You can see more informations about it here :

How to Prevent SQL Injection in PHP

 

Mohammad Ateieh
by Mohammad Ateieh , Software Engineering Manager , Bayt.com

in PDO and MySqli you can bind the parameters and then excute the query

another solution you can escape the parameters using "mysql_real_escape_string"

its all depends on what are you using to manipulate the sql statement

Arif Mohammad Mohiuddin
by Arif Mohammad Mohiuddin , Data Entry Chief & Manager , Mohammadia Enterprise

Stored Procedure

 

Muhammed Ajmal Seeraveetil
by Muhammed Ajmal Seeraveetil , Software Engineer , Wipro

Better always use XSS Filtering 

Asif Ahmad Rather
by Asif Ahmad Rather , Senior Software Engineer , Eresolute Consultant and Services pvt ltd.

the best and the simple way is use sql procedures and try to implement strict coding. dont b a loose coder. 

Mohammed Aldini
by Mohammed Aldini , Project Manager/Team Leader/Senior Software Engineer/System Analysis , TechBox Group

use mysql_escape_string function to avoid charectors for sql injection before the string with {} for example:"SELECT *FROM  `tablename`WHERE  fieldname = '{".mysql_escape_string($value)."}'"

Tanweer Ahmed
by Tanweer Ahmed , Application Developer , Department of Revenue,Registration and Land Reforms,Government of Jharkhand

Use Parameterized Query to prevent sql injection

mukhtar ahmed Ibrahim
by mukhtar ahmed Ibrahim , Software engineer , Norwegian tax administration

 

Best way to prevent sql injection is looking for correct input.  Use regular expressions and develop strategy for invalid input. Please remember pitfals. alternative representations. http://myhostname.com or http://194.71.105.29.

Biggest mistake:

.Not checking at all,

.Looking for incorrect input. 

Saad Ibrahim
by Saad Ibrahim , senior web developer , brandusocial

Beside The best things  that all Other developrs mention, the best thing u can do to avoid SQL injection, is FILTER ALL INPUTS , Nerver trust input from user.

One of the ways is using magic quotes at server level. Another one is using the function addslashes for each input, although it's not really nice.

Junais Vaisyar
by Junais Vaisyar , End-User Support , KAUST

use mysql_escape_string function to avoid charectors for sql injection before the string

More Questions Like This

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.