anon Posted December 28, 2007 Share Posted December 28, 2007 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/***/public_html/***/spider.php on line 13 Here is my current code - <?php $dbhost = '***'; $dbuser = '****'; $dbpass = '*****'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error with database'); $dbname = '****'; mysql_select_db($dbname); $getlist=mysql_query("SELECT u_id FROM addurl"); while($row=mysql_fetch_array($getlist)){ $text = file_get_contents($row[0]); mysql_query("insert into *** (content) values ($text)"); } ?> The code should fetch and index a page that has been specified in a database. Quote Link to comment https://forums.phpfreaks.com/topic/83456-help-with-mysql_fetch_array/ Share on other sites More sharing options...
rajivgonsalves Posted December 28, 2007 Share Posted December 28, 2007 try $getlist=mysql_query("SELECT u_id FROM addurl") or die("Query error ".mysql_error()); and let me know if you get any errors Quote Link to comment https://forums.phpfreaks.com/topic/83456-help-with-mysql_fetch_array/#findComment-424590 Share on other sites More sharing options...
anon Posted December 28, 2007 Author Share Posted December 28, 2007 I will try it, but the error is in line 13... Quote Link to comment https://forums.phpfreaks.com/topic/83456-help-with-mysql_fetch_array/#findComment-424591 Share on other sites More sharing options...
rajivgonsalves Posted December 28, 2007 Share Posted December 28, 2007 actually your syntax looks good, there can only be an error in connecting to the database, selecting a database, or the query.. Quote Link to comment https://forums.phpfreaks.com/topic/83456-help-with-mysql_fetch_array/#findComment-424592 Share on other sites More sharing options...
anon Posted December 28, 2007 Author Share Posted December 28, 2007 This is the error the Cron Daemon gave me\ "Query error No database selected" I did select a database though... Quote Link to comment https://forums.phpfreaks.com/topic/83456-help-with-mysql_fetch_array/#findComment-424594 Share on other sites More sharing options...
rajivgonsalves Posted December 28, 2007 Share Posted December 28, 2007 are you connecting to the correct host that has the db check that Quote Link to comment https://forums.phpfreaks.com/topic/83456-help-with-mysql_fetch_array/#findComment-424597 Share on other sites More sharing options...
anon Posted December 28, 2007 Author Share Posted December 28, 2007 I think I may have spelt the DB name wrong. Is it case-sensitive? Quote Link to comment https://forums.phpfreaks.com/topic/83456-help-with-mysql_fetch_array/#findComment-424599 Share on other sites More sharing options...
rajivgonsalves Posted December 28, 2007 Share Posted December 28, 2007 it should not be... but you can try it... Quote Link to comment https://forums.phpfreaks.com/topic/83456-help-with-mysql_fetch_array/#findComment-424600 Share on other sites More sharing options...
anon Posted December 28, 2007 Author Share Posted December 28, 2007 Nope, no luck Here's my code at the mo <?php $dbhost = 'localhost'; $dbuser = '***'; $dbpass = '****'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error with database'); $dbname = 'Direx'; mysql_select_db($dbname); $getlist=mysql_query("SELECT u_link FROM addurl") or die("Query error ".mysql_error()); while($row=mysql_fetch_array($getlist)){ $text = file_get_contents($row[0]); mysql_query("insert into Index (content) values ($text)"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/83456-help-with-mysql_fetch_array/#findComment-424601 Share on other sites More sharing options...
kenrbnsn Posted December 28, 2007 Share Posted December 28, 2007 Put an "or die" clause on the mysql_select_db() function: <?php mysql_select_db($dbname) or die("Problem selecting the database $dbname<br>" . mysql_error()); ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/83456-help-with-mysql_fetch_array/#findComment-424606 Share on other sites More sharing options...
anon Posted December 28, 2007 Author Share Posted December 28, 2007 Ok, I'll try that now. Just asking, is that a technique used by developers to find where the problem is? Quote Link to comment https://forums.phpfreaks.com/topic/83456-help-with-mysql_fetch_array/#findComment-424611 Share on other sites More sharing options...
anon Posted December 28, 2007 Author Share Posted December 28, 2007 The problem is in my password or something, because it says access denied. Quote Link to comment https://forums.phpfreaks.com/topic/83456-help-with-mysql_fetch_array/#findComment-424613 Share on other sites More sharing options...
PHP_PhREEEk Posted December 28, 2007 Share Posted December 28, 2007 If that doesn't get you going, the only thing I would try is: <?php $dbhost = 'localhost'; $dbuser = '***'; $dbpass = '****'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error with database'); $dbname = 'Direx'; mysql_select_db($dbname, $conn); // rest of your script PhREEEk Quote Link to comment https://forums.phpfreaks.com/topic/83456-help-with-mysql_fetch_array/#findComment-424615 Share on other sites More sharing options...
PHP_PhREEEk Posted December 28, 2007 Share Posted December 28, 2007 Please, when we are trying to prompt you for error msgs, don't just post "it says access denied". Copy the entire error right off of the screen.. all of it... then paste it here. PhREEEk Quote Link to comment https://forums.phpfreaks.com/topic/83456-help-with-mysql_fetch_array/#findComment-424616 Share on other sites More sharing options...
janim Posted December 28, 2007 Share Posted December 28, 2007 you need this : <?php $getlist=mysql_query("SELECT u_id FROM addurl"); // add this if statement if(mysql_num_rows($getlist)){ while($row=mysql_fetch_array($getlist)){ $text = file_get_contents($row[0]); mysql_query("insert into *** (content) values ($text)"); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/83456-help-with-mysql_fetch_array/#findComment-424620 Share on other sites More sharing options...
kenrbnsn Posted December 28, 2007 Share Posted December 28, 2007 The OP isn't even connecting to the database. Ken Quote Link to comment https://forums.phpfreaks.com/topic/83456-help-with-mysql_fetch_array/#findComment-424633 Share on other sites More sharing options...
anon Posted December 28, 2007 Author Share Posted December 28, 2007 Problem selecting the database Direx<br>Access denied for user '*******'@'localhost' to database 'Direx' Quote Link to comment https://forums.phpfreaks.com/topic/83456-help-with-mysql_fetch_array/#findComment-424667 Share on other sites More sharing options...
PHP_PhREEEk Posted December 28, 2007 Share Posted December 28, 2007 Interesting that the error does not state 'Using Password YES' or 'NO' for that matter... I've got to run some errands this morning, so I'll leave it to someone else to walk him through verifying the user. PhREEEk Quote Link to comment https://forums.phpfreaks.com/topic/83456-help-with-mysql_fetch_array/#findComment-424738 Share on other sites More sharing options...
revraz Posted December 28, 2007 Share Posted December 28, 2007 $dbhost = '***'; $dbuser = '****'; $dbpass = '*****'; $dbname = '****'; One of these is wrong, you need to figure out which one and fix it. Quote Link to comment https://forums.phpfreaks.com/topic/83456-help-with-mysql_fetch_array/#findComment-424741 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.