Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,472
There are 1319 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

How to prevent SQL injections?

Thread title: How to prevent SQL injections?
Closed Thread  
Page 1 of 2 1 2 >
    Thread tools Search this thread Display Modes  
02-28-2007, 06:36 PM
#1
Sam Granger is offline Sam Granger
Status: Request a custom title
Join date: Feb 2005
Location: The Netherlands
Expertise:
Software:
 
Posts: 2,616
iTrader: 19 / 88%
 

Sam Granger is on a distinguished road

Send a message via MSN to Sam Granger

  Old  How to prevent SQL injections?

How can you prevent SQL injections? I've heard the best way is not to use variables in SQL queries but isn't this really hard to achieve when making a complex script?

02-28-2007, 06:38 PM
#2
Sam Granger is offline Sam Granger
Status: Request a custom title
Join date: Feb 2005
Location: The Netherlands
Expertise:
Software:
 
Posts: 2,616
iTrader: 19 / 88%
 

Sam Granger is on a distinguished road

Send a message via MSN to Sam Granger

  Old

Whoops,s orry should of done a bit more research! Found info, please close topic.

02-28-2007, 07:50 PM
#3
localhost is offline localhost
localhost's Avatar
Status: Dediport Hosting
Join date: Jul 2006
Location: Berkshire
Expertise: programming, business
Software: Dreamweaver
 
Posts: 1,316
iTrader: 17 / 100%
 

localhost is on a distinguished road

  Old

Tell your answer then other people can know at least..

02-28-2007, 08:08 PM
#4
Xuxa is offline Xuxa
Status: Request a custom title
Join date: Feb 2006
Location: USA
Expertise:
Software:
 
Posts: 1,076
iTrader: 17 / 95%
 

Xuxa is on a distinguished road

Send a message via MSN to Xuxa

  Old

You can use magic quotes....

02-28-2007, 09:16 PM
#5
bluesaga is offline bluesaga
Status: Member
Join date: Feb 2007
Location:
Expertise:
Software:
 
Posts: 137
iTrader: 1 / 100%
 

bluesaga is on a distinguished road

  Old

PHP Code:
function return_mysql_entry($var)
{
    if(
gettype($var) != "integer")
        return 
"'".mysql_escape_string($var)."'";
    else
        return 
$var;
}

//Usage
$name $_GET['name'];
$query "SELECT * FROM table WHERE name=".return_mysql_entry($name); 

02-28-2007, 09:48 PM
#6
Xi0s is offline Xi0s
Status: Sin Binner
Join date: Dec 2006
Location: Huddersfield, UK
Expertise:
Software:
 
Posts: 384
iTrader: 3 / 83%
 

Xi0s is on a distinguished road

Send a message via MSN to Xi0s

  Old

bluesaga has it there, mysql_escape_string() is the way forward .

02-28-2007, 09:49 PM
#7
prasunsen is offline prasunsen
Status: Junior Member
Join date: Dec 2006
Location:
Expertise:
Software:
 
Posts: 52
iTrader: 0 / 0%
 

prasunsen is on a distinguished road

Send a message via ICQ to prasunsen

  Old

I use mysql_real_escape_string and always put in quotes the arguments which might come from user input

02-28-2007, 10:18 PM
#8
Xuxa is offline Xuxa
Status: Request a custom title
Join date: Feb 2006
Location: USA
Expertise:
Software:
 
Posts: 1,076
iTrader: 17 / 95%
 

Xuxa is on a distinguished road

Send a message via MSN to Xuxa

  Old

I use OOP which uses Magic Quotes

02-28-2007, 10:39 PM
#9
RaZoR^ is offline RaZoR^
RaZoR^'s Avatar
Status: Member
Join date: Feb 2006
Location:
Expertise:
Software:
 
Posts: 191
iTrader: 1 / 100%
 

RaZoR^ is on a distinguished road

  Old

What does OOP have to do with escaping characters in HTTP strings? :s

Code:
<?php

// If magic quotes are enabled, strip slashes from all user data
function stripslashes_recursive($var) {
	return (is_array($var) ? array_map('stripslashes_recursive', $var) : stripslashes($var));
}

if (get_magic_quotes_gpc()) {
	$_GET = stripslashes_recursive($_GET);
	$_POST = stripslashes_recursive($_POST);
	$_COOKIE = stripslashes_recursive($_COOKIE);
}

?>
(Source: http://snippets.dzone.com/posts/show/324).

02-28-2007, 10:59 PM
#10
Andrew R is offline Andrew R
Status: Request a custom title
Join date: Dec 2005
Location: Arizona
Expertise:
Software:
 
Posts: 5,200
iTrader: 17 / 95%
 

Andrew R is on a distinguished road

  Old

mysql_real_escape_string()

There are no other functions needed.

Closed Thread  
Page 1 of 2 1 2 >


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed