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. 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 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... 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.. 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... 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 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? 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... 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)"); } ?> 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 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? 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. 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 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 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)"); } } ?> 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 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' 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 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. 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
Archived
This topic is now archived and is closed to further replies.