<?xml version="1.0" encoding="utf-8" ?><rss version="2.0" xml:base="https://www.webmaster-forums.net/crss/node/1039364" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title></title>
    <link>https://www.webmaster-forums.net/crss/node/1039364</link>
    <description></description>
    <language>en</language>
          <item>
    <title></title>
    <link>https://www.webmaster-forums.net/web-database-development/multiple-delete-mysql-loop#comment-1223586</link>
    <description> &lt;p&gt;You really need to run all your user input through verification before passing it to a SQL query.  At least use mysql_escape_string() to escape the strings to avoid a SQL injection attack that could devastate your data integrity and confidentiality.&lt;/p&gt;
 </description>
     <pubDate>Mon, 27 Aug 2007 02:19:05 +0000</pubDate>
 <dc:creator>FrankR</dc:creator>
 <guid isPermaLink="false">comment 1223586 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/web-database-development/multiple-delete-mysql-loop#comment-1223235</link>
    <description> &lt;blockquote class=&quot;bb-quote-body&quot;&gt;&lt;p&gt;Quote: if the if(mysql_affected_rows($result) == 0) never gets executed (i.e. it&#039;s never 0)&lt;br /&gt;
then the $delete_errors[$var1] = TRUE is always empty&lt;br /&gt;
and then the foreach further down returned an error&lt;br /&gt;
Warning: Invalid argument supplied for foreach() in /etc/etc/etc line 10&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;That&#039;s because I gave you crappy code (hey, I&#039;m in a hotel room, it&#039;s hard to write code in here). mysql_affected_rows doesn&#039;t need that $result argument, so take it out. Also took out == 0 and replaced it with less than 1 (mysql_affected_rows doesn&#039;t always return 0 when it doesn&#039;t affect rows)&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; &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;if(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;mysql_affected_rows&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;() &amp;lt; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF8000&quot;&gt;// nothing was deleted&lt;br /&gt;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$delete_errors&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$var1&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;] = &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;TRUE&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color: #FF8000&quot;&gt;// flag it&lt;br /&gt;&amp;nbsp; &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;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;That hopefully will solve most of the errors you are getting.&lt;/p&gt;
 </description>
     <pubDate>Sun, 19 Aug 2007 02:45:03 +0000</pubDate>
 <dc:creator>teammatt3</dc:creator>
 <guid isPermaLink="false">comment 1223235 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/web-database-development/multiple-delete-mysql-loop#comment-1223234</link>
    <description> &lt;p&gt;yes, thanks for those confirmations&lt;/p&gt;
&lt;p&gt;That code works fine apart from one thing&lt;/p&gt;
&lt;p&gt;if the  if(mysql_affected_rows($result) == 0) never gets executed (i.e. it&#039;s never 0)&lt;br /&gt;
then the  $delete_errors[$var1] = TRUE is always empty&lt;br /&gt;
and then the foreach further down returned an error&lt;br /&gt;
Warning: Invalid argument supplied for foreach() in /etc/etc/etc line 10&lt;/p&gt;
&lt;p&gt;I noticed this about foreach. if the $var you use in the foreach is empty, it always returns an error&lt;br /&gt;
maybe there is something I am missing or don&#039;t know?&lt;/p&gt;
&lt;p&gt;also once that page is complete and files selected for deletion are successfully deleted there is a css button to go to another page&lt;br /&gt;
if I go to that page and then click the browser back button&lt;br /&gt;
I get that error&lt;br /&gt;
Warning: Invalid argument supplied for foreach() in /etc/etc/etc line 10&lt;/p&gt;
&lt;p&gt;to avoid it I just put an IF clause in before the foreach, which worked&lt;/p&gt;
&lt;p&gt;but then of course any user playing with the url or clicking back still gets that error for the FOREACH that is used on the mysql query&lt;/p&gt;
&lt;p&gt;So I had to put a full clause in for the whole page (global var assigned to find where user came from etc)&lt;/p&gt;
&lt;p&gt;Would be interesting to learn how to avoid that&lt;br /&gt;
I cannot find anything on google or php net&lt;/p&gt;
&lt;p&gt;cheers&lt;/p&gt;
 </description>
     <pubDate>Sun, 19 Aug 2007 01:13:31 +0000</pubDate>
 <dc:creator>greg</dc:creator>
 <guid isPermaLink="false">comment 1223234 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/web-database-development/multiple-delete-mysql-loop#comment-1223215</link>
    <description> &lt;blockquote class=&quot;bb-quote-body&quot;&gt;&lt;p&gt;Quote: firstly, will MYSQL query in that loop close its link to the DB on each loop for each item? or will it be efficient in its loop by keeping it open until loop finished?&lt;br /&gt;
if not, what is the best way?&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;I am pretty sure MySQL closes its link at the end of the page automatically.&lt;/p&gt;
&lt;blockquote class=&quot;bb-quote-body&quot;&gt;&lt;p&gt;Quote: So is it possible to put in that loop something that on each loop will identify that there wasn&#039;t a DB match, and assign the data for the current loop ($var1 and $var2) to something it will later remember and then continue looping?&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;I think all you would need is that delete query, and mysql_affected_rows(). Something like &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;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;foreach(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$_GET&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;urldata&#039;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;] as &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$var1&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$var2&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; &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;DELETE...FROM...WHERE\&quot;;&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$result&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt; = mysql_query(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$sql&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;);&lt;br /&gt;&lt;br /&gt;&amp;nbsp; if(mysql_affected_rows(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$result&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;) == 0) // nothing was deleted&lt;br /&gt;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$delete_errors&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$var1&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt; = TRUE; // flag it&lt;br /&gt;&amp;nbsp; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// print out error for each item in the &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$delete_errors&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt; array&lt;br /&gt;foreach(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$delete_errors&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt; as &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$var1&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt; =&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$var2&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; echo \&quot;error with &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$var1&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;\&quot;;&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;I didn&#039;t check my code, but I think you can get the idea of what to do from it. Run the query, check to see if any rows were affected, if 0 rows were affected, make note of it in an array, and print out the array when the other loop is done.&lt;/p&gt;
&lt;blockquote class=&quot;bb-quote-body&quot;&gt;&lt;p&gt;Quote: I dont know if the MYSQL QUERY will exit on a false query, if the $var1 or $var2 didnt match at any point anything in the DB will it stop?&lt;br /&gt;
or continue through the loop as I need it to?&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;&lt;a href=&quot;http://us2.php.net/mysql_query&quot; class=&quot;bb-url&quot;&gt;&lt;br /&gt;
mysql_query returns false&lt;/a&gt; on a bad query, but it does not exit the loop because of it (although you could write some code to do that if you wanted).&lt;/p&gt;
 </description>
     <pubDate>Sat, 18 Aug 2007 17:14:47 +0000</pubDate>
 <dc:creator>teammatt3</dc:creator>
 <guid isPermaLink="false">comment 1223215 at https://www.webmaster-forums.net</guid>
  </item>
  </channel>
</rss>
