hellonoko Posted April 23, 2009 Share Posted April 23, 2009 I am using a simple query that I have basically copied from another part of my code where it works perfectly but for some reason I can't see it errors now: <?php // connect the db include_once "connectotron.php"; echo 'updating file sizes...<br>'; $query = mysql_query("SELECT * FROM `mp3links` WHERE `scraped` = '1'"); while ($row = mysql_fetch_array($query)) { $file = '/home2/sharingi/public_html/scrape/scraped/'.$row[sourcefile]; echo $file_size = filesize($file); echo '<br>'; $update = $row[sourcefile]; // set the file size $query = "UPDATE `mp3links` SET `size` = '$file_size' WHERE `sourcefile` = '$update'"; $result = mysql_query($query) or die (mysql_error()); } ?> Error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home2/sharingi/public_html/scrape/update_sizes.php on line 10 When I comment out the last two lines of my code it works fine listing all the file sizes. Is there something wrong with my update query I cant see? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/155323-solved-simple-query-failing/ Share on other sites More sharing options...
adam291086 Posted April 23, 2009 Share Posted April 23, 2009 try echoing out you variables to make sure they contain information Quote Link to comment https://forums.phpfreaks.com/topic/155323-solved-simple-query-failing/#findComment-817168 Share on other sites More sharing options...
hellonoko Posted April 23, 2009 Author Share Posted April 23, 2009 They all seem to echo fine. When I include the update it will echo the first row of variables and then the error. Quote Link to comment https://forums.phpfreaks.com/topic/155323-solved-simple-query-failing/#findComment-817172 Share on other sites More sharing options...
adam291086 Posted April 23, 2009 Share Posted April 23, 2009 change $update = $row[sourcefile]; $update = $row['sourcefile']; thats one error but nothing to do with line 10, not sure whats causeing that error. Quote Link to comment https://forums.phpfreaks.com/topic/155323-solved-simple-query-failing/#findComment-817176 Share on other sites More sharing options...
adam291086 Posted April 23, 2009 Share Posted April 23, 2009 also try $query = mysql_query("SELECT * FROM `mp3links` WHERE `scraped` = '1'"); to $query = mysql_query("SELECT * FROM mp3links WHERE scraped = '1'"); Quote Link to comment https://forums.phpfreaks.com/topic/155323-solved-simple-query-failing/#findComment-817179 Share on other sites More sharing options...
hellonoko Posted April 23, 2009 Author Share Posted April 23, 2009 I set the code to this: // set the file size $result = mysql_query("UPDATE `mp3links` SET `size` = '$file_size' WHERE `id` = '$update'") or die (mysql_error()); Same exact thing just one line and it worked... any idea why? Quote Link to comment https://forums.phpfreaks.com/topic/155323-solved-simple-query-failing/#findComment-817181 Share on other sites More sharing options...
adam291086 Posted April 23, 2009 Share Posted April 23, 2009 Its because you are going through the while loop using $query and your trying to re set $query in the while loop and therefore messing up the while loop. Quote Link to comment https://forums.phpfreaks.com/topic/155323-solved-simple-query-failing/#findComment-817186 Share on other sites More sharing options...
hellonoko Posted April 23, 2009 Author Share Posted April 23, 2009 Ahhh. Ok so either how I have changed it OR $query1 $query2 so they do not conflict. Quote Link to comment https://forums.phpfreaks.com/topic/155323-solved-simple-query-failing/#findComment-817189 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.