<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: SQL Injection: How To Prevent Security Flaws In PHP / MySQL</title>
	<atom:link href="http://www.learnphponline.com/security/sql-injection-prevention-mysql-php/feed" rel="self" type="application/rss+xml" />
	<link>http://www.learnphponline.com/security/sql-injection-prevention-mysql-php</link>
	<description>Learn PHP Online</description>
	<lastBuildDate>Fri, 23 Dec 2011 17:09:11 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
	<item>
		<title>By: shaheen</title>
		<link>http://www.learnphponline.com/security/sql-injection-prevention-mysql-php/comment-page-1#comment-13402</link>
		<dc:creator>shaheen</dc:creator>
		<pubDate>Thu, 29 Sep 2011 05:54:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.learnphponline.com/?p=37#comment-13402</guid>
		<description>for simple sql, how to prevent sql injection in php? for example select * from table1.

Thanks</description>
		<content:encoded><![CDATA[<p>for simple sql, how to prevent sql injection in php? for example select * from table1.</p>
<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ch4p1</title>
		<link>http://www.learnphponline.com/security/sql-injection-prevention-mysql-php/comment-page-1#comment-12679</link>
		<dc:creator>ch4p1</dc:creator>
		<pubDate>Sat, 06 Aug 2011 17:31:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.learnphponline.com/?p=37#comment-12679</guid>
		<description>Hi ! 

Instead of use foreach, you can use array_map or array_walk : 

function escape($var) {
	return mysql_real_escape_string($var);
}

$post = array_map(&quot;escape&quot;, $_POST);

See u !</description>
		<content:encoded><![CDATA[<p>Hi ! </p>
<p>Instead of use foreach, you can use array_map or array_walk : </p>
<p>function escape($var) {<br />
	return mysql_real_escape_string($var);<br />
}</p>
<p>$post = array_map(&#8220;escape&#8221;, $_POST);</p>
<p>See u !</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Robson Junior</title>
		<link>http://www.learnphponline.com/security/sql-injection-prevention-mysql-php/comment-page-1#comment-12420</link>
		<dc:creator>Robson Junior</dc:creator>
		<pubDate>Fri, 15 Jul 2011 19:35:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.learnphponline.com/?p=37#comment-12420</guid>
		<description>Amazing article. I was googling for a quick and easy way to prevent sql injection and i&#039;m very glad to find this site. Information is very technical and fun to read at the same time. :)
Thanks so much for sharing this</description>
		<content:encoded><![CDATA[<p>Amazing article. I was googling for a quick and easy way to prevent sql injection and i&#8217;m very glad to find this site. Information is very technical and fun to read at the same time. <img src='http://www.learnphponline.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
Thanks so much for sharing this</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael W</title>
		<link>http://www.learnphponline.com/security/sql-injection-prevention-mysql-php/comment-page-1#comment-12184</link>
		<dc:creator>Michael W</dc:creator>
		<pubDate>Wed, 29 Jun 2011 06:17:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.learnphponline.com/?p=37#comment-12184</guid>
		<description>&lt;blockquote&gt;“SELECT * FROM Products WHERE ID = “.mysql_real_escape_string($_GET[&quot;id&quot;]);

Doing this would bypass mysql_real_escape_string:
vulnpage.php?id=1 UNION SELECT * FROM Users;&lt;/blockquote&gt;

That is because that statement is just poor coding.

“SELECT * FROM `Products` WHERE `ID` = &quot;.mysql_real_escape_string($_GET[&quot;id&quot;].“&#039;&quot;);

That is a MUCH better way to write that statement that subverts SQL injections with the use of mysql_real_escape_string().</description>
		<content:encoded><![CDATA[<blockquote><p>“SELECT * FROM Products WHERE ID = “.mysql_real_escape_string($_GET["id"]);</p>
<p>Doing this would bypass mysql_real_escape_string:<br />
vulnpage.php?id=1 UNION SELECT * FROM Users;</p></blockquote>
<p>That is because that statement is just poor coding.</p>
<p>“SELECT * FROM `Products` WHERE `ID` = &#8220;.mysql_real_escape_string($_GET["id"].“&#8217;&#8221;);</p>
<p>That is a MUCH better way to write that statement that subverts SQL injections with the use of mysql_real_escape_string().</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Larry</title>
		<link>http://www.learnphponline.com/security/sql-injection-prevention-mysql-php/comment-page-1#comment-11963</link>
		<dc:creator>Larry</dc:creator>
		<pubDate>Mon, 13 Jun 2011 00:53:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.learnphponline.com/?p=37#comment-11963</guid>
		<description>I sincerely hope that coders are paraphrasing their code and not actually using code such as &quot;Select * from users where user = mysql_real_escape_string($_POST[user]... etc. etc.

At the VERY minimum coders need to be using a database abstraction layer that includes any necessary data conversions and safeguards.</description>
		<content:encoded><![CDATA[<p>I sincerely hope that coders are paraphrasing their code and not actually using code such as &#8220;Select * from users where user = mysql_real_escape_string($_POST[user]&#8230; etc. etc.</p>
<p>At the VERY minimum coders need to be using a database abstraction layer that includes any necessary data conversions and safeguards.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Larry</title>
		<link>http://www.learnphponline.com/security/sql-injection-prevention-mysql-php/comment-page-1#comment-11962</link>
		<dc:creator>Larry</dc:creator>
		<pubDate>Mon, 13 Jun 2011 00:44:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.learnphponline.com/?p=37#comment-11962</guid>
		<description>No, Chris, hardcoded statements do not suffer from Sql injection attacks. An Sql injection attack is exactly that, an attack upon a web site from an outside source.</description>
		<content:encoded><![CDATA[<p>No, Chris, hardcoded statements do not suffer from Sql injection attacks. An Sql injection attack is exactly that, an attack upon a web site from an outside source.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris</title>
		<link>http://www.learnphponline.com/security/sql-injection-prevention-mysql-php/comment-page-1#comment-11951</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Sun, 12 Jun 2011 11:22:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.learnphponline.com/?p=37#comment-11951</guid>
		<description>Are php sql statements only at risk from injection when you&#039;re using user-input data as part of the sql string?

For example, if you have statements like:

$con = mysql_connect(&quot;localhost&quot;,&quot;myname&quot;,&quot;password123&quot;);
mysql_select_db(&quot;mydb&quot;, $con);
$result = mysql_query(&quot;SELECT * FROM mytable&quot;);
while($row = mysql_fetch_array($result))
{...etc etc etc

all hard coded into the php file and not using user input, is it at risk?</description>
		<content:encoded><![CDATA[<p>Are php sql statements only at risk from injection when you&#8217;re using user-input data as part of the sql string?</p>
<p>For example, if you have statements like:</p>
<p>$con = mysql_connect(&#8220;localhost&#8221;,&#8221;myname&#8221;,&#8221;password123&#8243;);<br />
mysql_select_db(&#8220;mydb&#8221;, $con);<br />
$result = mysql_query(&#8220;SELECT * FROM mytable&#8221;);<br />
while($row = mysql_fetch_array($result))<br />
{&#8230;etc etc etc</p>
<p>all hard coded into the php file and not using user input, is it at risk?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: JD</title>
		<link>http://www.learnphponline.com/security/sql-injection-prevention-mysql-php/comment-page-1#comment-11710</link>
		<dc:creator>JD</dc:creator>
		<pubDate>Fri, 27 May 2011 04:49:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.learnphponline.com/?p=37#comment-11710</guid>
		<description>Thank you so much for the point that you must be connected to mysql for the mysql_real_escape_string() to work!! I had this set to my variables at the beginning of the code and couldn&#039;t get it to work until I read your post.

mysql_connect(&quot;localhost&quot;, &quot;username&quot;, &quot;password&quot;);
$var = mysql_real_escape_string(stripslashes($_POST[&#039;var&#039;]));

then I could use $var all nice and clean

THANKS AGAIN :)</description>
		<content:encoded><![CDATA[<p>Thank you so much for the point that you must be connected to mysql for the mysql_real_escape_string() to work!! I had this set to my variables at the beginning of the code and couldn&#8217;t get it to work until I read your post.</p>
<p>mysql_connect(&#8220;localhost&#8221;, &#8220;username&#8221;, &#8220;password&#8221;);<br />
$var = mysql_real_escape_string(stripslashes($_POST['var']));</p>
<p>then I could use $var all nice and clean</p>
<p>THANKS AGAIN <img src='http://www.learnphponline.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Edd lol</title>
		<link>http://www.learnphponline.com/security/sql-injection-prevention-mysql-php/comment-page-1#comment-10274</link>
		<dc:creator>Edd lol</dc:creator>
		<pubDate>Wed, 06 Apr 2011 02:39:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.learnphponline.com/?p=37#comment-10274</guid>
		<description>anywhere you have an SQL query that grabs typed user input and sends it to the database.

you can put it on the variable, on the right hand side, when you assign it the value of the user input.

or if you don&#039;t use variables you can put the post/get/request function inside of it.</description>
		<content:encoded><![CDATA[<p>anywhere you have an SQL query that grabs typed user input and sends it to the database.</p>
<p>you can put it on the variable, on the right hand side, when you assign it the value of the user input.</p>
<p>or if you don&#8217;t use variables you can put the post/get/request function inside of it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ad</title>
		<link>http://www.learnphponline.com/security/sql-injection-prevention-mysql-php/comment-page-1#comment-10203</link>
		<dc:creator>Ad</dc:creator>
		<pubDate>Mon, 04 Apr 2011 21:16:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.learnphponline.com/?p=37#comment-10203</guid>
		<description>ubtng is right &quot;mysqli_real_escape_string&quot; does not defend against SQL Injection attacks and prepared statements and input validation are the way to go. Correct me if I&#039;m wrong, but you can&#039;t batch statements in MySQL? So \’; DESC users; – wouldn&#039;t work...

You can however inject into numeric values where there is no single quote to break out of so if the site contains the following code:
&quot;SELECT * FROM Products WHERE ID = &quot;.mysql_real_escape_string($_GET[&quot;id&quot;]); 

Doing this would bypass mysql_real_escape_string:
vulnpage.php?id=1 UNION SELECT * FROM Users;</description>
		<content:encoded><![CDATA[<p>ubtng is right &#8220;mysqli_real_escape_string&#8221; does not defend against SQL Injection attacks and prepared statements and input validation are the way to go. Correct me if I&#8217;m wrong, but you can&#8217;t batch statements in MySQL? So \’; DESC users; – wouldn&#8217;t work&#8230;</p>
<p>You can however inject into numeric values where there is no single quote to break out of so if the site contains the following code:<br />
&#8220;SELECT * FROM Products WHERE ID = &#8220;.mysql_real_escape_string($_GET["id"]); </p>
<p>Doing this would bypass mysql_real_escape_string:<br />
vulnpage.php?id=1 UNION SELECT * FROM Users;</p>
]]></content:encoded>
	</item>
</channel>
</rss>

