Andrew R Posted January 23, 2007 Share Posted January 23, 2007 Hi guys.What is the recommend way to protect against an SQL injection on the following query?[code]$query_qy = "SELECT * FROM tablename where name = '$name' && date = '$date'";$qy= mysql_query($query_qy) or die(mysql_error());$row_qy = mysql_fetch_assoc($qy);[/code]Cheers Link to comment https://forums.phpfreaks.com/topic/35413-best-way-to-protect-against-sql-injection/ Share on other sites More sharing options...
redbullmarky Posted January 23, 2007 Share Posted January 23, 2007 a good ol' dose of [url=http://www.php.net/mysql_real_escape_string]mysql_real_escape_string[/url] often does the trick.[code]<?php$name = mysql_real_escape_string($name);$date = mysql_real_escape_string($date);$query_qy = "SELECT * FROM tablename where name = '$name' && date = '$date'";$qy= mysql_query($query_qy) or die(mysql_error());$row_qy = mysql_fetch_assoc($qy);?>[/code] Link to comment https://forums.phpfreaks.com/topic/35413-best-way-to-protect-against-sql-injection/#findComment-167512 Share on other sites More sharing options...
Orio Posted January 23, 2007 Share Posted January 23, 2007 Dont forget to use stripslashes() if magic_quotes is set, before using mysql_real_escape_string(). See more info in the mysql_real_escape_string() function in php.net, there's a very good explanation over there.Also, check out the info about [url=http://il2.php.net/manual/en/security.database.sql-injection.php]sql injections[/url] in the manual- it's a great resource.Orio. Link to comment https://forums.phpfreaks.com/topic/35413-best-way-to-protect-against-sql-injection/#findComment-167518 Share on other sites More sharing options...
Andrew R Posted January 23, 2007 Author Share Posted January 23, 2007 Cheers for the help. Is there any other ways I could protect my inputs and outputs? Link to comment https://forums.phpfreaks.com/topic/35413-best-way-to-protect-against-sql-injection/#findComment-167596 Share on other sites More sharing options...
Snooble Posted January 23, 2007 Share Posted January 23, 2007 restrict the use of hex.Snooble Link to comment https://forums.phpfreaks.com/topic/35413-best-way-to-protect-against-sql-injection/#findComment-167597 Share on other sites More sharing options...
redbullmarky Posted January 23, 2007 Share Posted January 23, 2007 [quote author=Snooble link=topic=123708.msg511789#msg511789 date=1169588842]restrict the use of hex.Snooble[/quote] ??? ??? Link to comment https://forums.phpfreaks.com/topic/35413-best-way-to-protect-against-sql-injection/#findComment-167638 Share on other sites More sharing options...
Snooble Posted January 23, 2007 Share Posted January 23, 2007 %53%45%4c%45%43%54%20%2a%20%46%52%4f%4d%20%2aTry inputting that into your DB.Snooble Link to comment https://forums.phpfreaks.com/topic/35413-best-way-to-protect-against-sql-injection/#findComment-167641 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.