<?xml version="1.0" encoding="utf-8" ?><rss version="2.0" xml:base="https://www.webmaster-forums.net/crss/node/1040304" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title></title>
    <link>https://www.webmaster-forums.net/crss/node/1040304</link>
    <description></description>
    <language>en</language>
          <item>
    <title></title>
    <link>https://www.webmaster-forums.net/web-database-development/correct-syntax-mysql-query#comment-1227119</link>
    <description> &lt;p&gt;Good point calculator, you can also cast the value as an int: &lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #000000&quot;&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;&amp;lt;?php&lt;br /&gt;$number1 &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= (int) &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;mysql_real_escape_string&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$_POST&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;number1&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;]; &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$number2 &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= (int) &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;mysql_real_escape_string&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$_POST&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;number2&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;]; &lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #FF8000&quot;&gt;/* then run the query */ &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$sql &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= \&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;UPDATE goods SET stock = &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$number1&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;, WHERE item = &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$number2&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;; &lt;br /&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;That&#039;ll make sure they&#039;re numerics. Both methods will work. &lt;img src=&quot;https://www.webmaster-forums.net/misc/smileys/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; class=&quot;smiley-content&quot; /&gt;&lt;/p&gt;
 </description>
     <pubDate>Sat, 08 Dec 2007 05:10:49 +0000</pubDate>
 <dc:creator>JeevesBond</dc:creator>
 <guid isPermaLink="false">comment 1227119 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/web-database-development/correct-syntax-mysql-query#comment-1227057</link>
    <description> &lt;p&gt;if the posted values can only be number I would add an extra layer of security by checking if the $_post are numeric using the built-in php is_numeric() function.&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;if(is_numeric($_POST[&amp;#039;number1&amp;#039;]) &amp;amp;&amp;amp; is_numeric($_POST[&amp;#039;number2&amp;#039;])){&lt;br /&gt;$number1 = mysql_real_escape_string($_POST[&amp;#039;number1&amp;#039;]);&lt;br /&gt;$number2 = mysql_real_escape_string($_POST[&amp;#039;number2&amp;#039;]);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/* then run the query */&lt;br /&gt;&lt;br /&gt;$sql = &amp;quot;UPDATE goods SET stock = $number1, WHERE item = $number2;&lt;/code&gt;&lt;/div&gt;&#039;&lt;/p&gt;
&lt;p&gt;I know it&#039;s not necessary, but I think it then becomes a coding practice.&lt;/p&gt;
&lt;p&gt;As an additional comment, if you know what calues can be chosen, ie values from a drop down menu, use the switch/case to make sure that the value entered is valid.&lt;/p&gt;
&lt;p&gt;And as a final comment - after that I shut up &lt;img src=&quot;https://www.webmaster-forums.net/misc/smileys/wink.png&quot; title=&quot;Wink&quot; alt=&quot;Wink&quot; class=&quot;smiley-content&quot; /&gt; - read Chris Shiflett excellent &lt;a href=&quot;http://phpsecurity.org/&quot; class=&quot;bb-url&quot;&gt;Essential PHP Security&lt;/a&gt; book.&lt;/p&gt;
 </description>
     <pubDate>Thu, 06 Dec 2007 13:44:14 +0000</pubDate>
 <dc:creator>calculator</dc:creator>
 <guid isPermaLink="false">comment 1227057 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/web-database-development/correct-syntax-mysql-query#comment-1227047</link>
    <description> &lt;p&gt;pr0gramm3r writes wise words. Take heed. PHP can be rather insecure if used improperly.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://www.webmaster-forums.net/misc/smileys/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; class=&quot;smiley-content&quot; /&gt;&lt;/p&gt;
 </description>
     <pubDate>Thu, 06 Dec 2007 07:49:18 +0000</pubDate>
 <dc:creator>JeevesBond</dc:creator>
 <guid isPermaLink="false">comment 1227047 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/web-database-development/correct-syntax-mysql-query#comment-1227034</link>
    <description> &lt;p&gt;The syntax is technically correct, but you should never use $_GET or $_POST variables directly in queries.&lt;/p&gt;
&lt;p&gt;If I was a malicious user, I could send whatever I want to that script.  I could make $_POST[&#039;number2&#039;] equal...&lt;br /&gt;
&lt;code&gt;2; DROP TABLE goods;&lt;/code&gt;&#039;&lt;br /&gt;
...which would drop that table.  Simple yet devastating.  There are plenty of other malicious strings that could be injected into a query.&lt;/p&gt;
&lt;p&gt;Simple way to fix it: run all values you take from a user through the mysql_real_escape_string() function.&lt;br /&gt;
&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #000000&quot;&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;&amp;lt;?php&lt;br /&gt;$number1 &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;mysql_real_escape_string&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$_POST&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;number1&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;];&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$number2 &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;mysql_real_escape_string&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$_POST&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;number2&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;];&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #FF8000&quot;&gt;/* then run the query */&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$sql &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= \&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;UPDATE goods SET stock = &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$number1&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;, WHERE item = &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$number2&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;;&lt;br /&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;/p&gt;
 </description>
     <pubDate>Thu, 06 Dec 2007 03:40:10 +0000</pubDate>
 <dc:creator>pr0gr4mm3r</dc:creator>
 <guid isPermaLink="false">comment 1227034 at https://www.webmaster-forums.net</guid>
  </item>
  </channel>
</rss>
