anon Posted January 1, 2008 Share Posted January 1, 2008 Here is the code <? // Make mysql connection below $mysql_conn = @mysql_connect("localhost", "****", "***") or die("Could not connect to the Database, Please send us an e-mail in the contact section"); @mysql_select_db("******", $mysql_conn) or die("DataBase does not exist"); $url = mysql_query("SELECT u_id FROM addurl") or die("Query error ".mysql_error()); // The HTML file will be put into a string called $page $page = file_get_contents($url); // Insert into Database; mysql_query("insert into stevedex values ($page)"); ?> I run it through Cron, I get this error <br /> <b>Warning</b>: file_get_contents() expects parameter 1 to be string, resource given in <b>/home/****/public_html/***/thespider.php</b> on line <b>11</b><br /> Why? Quote Link to comment https://forums.phpfreaks.com/topic/83989-help-with-this-code/ Share on other sites More sharing options...
Barand Posted January 1, 2008 Share Posted January 1, 2008 Exactly as it says on the tin. $url needs to be a string (filename or variable containing a filename) Your $url is a resource handle to the results of the query. Quote Link to comment https://forums.phpfreaks.com/topic/83989-help-with-this-code/#findComment-427396 Share on other sites More sharing options...
kopytko Posted January 1, 2008 Share Posted January 1, 2008 You need to use mysql_fetch_ function, like this: <?php // ... $url = mysql_query("SELECT u_id FROM addurl") or die("Query error ".mysql_error()); $row = mysql_fetch_row($url); $page = file_get_contents($row[0]); // ..... ?> mysql_query returns resource, not data. See manual for more info. Quote Link to comment https://forums.phpfreaks.com/topic/83989-help-with-this-code/#findComment-427397 Share on other sites More sharing options...
anon Posted January 1, 2008 Author Share Posted January 1, 2008 Different error now. <br /> <b>Parse error</b>: syntax error, unexpected $end in <b>/home/******/public_html/****/thespider.php</b> on line <b>21</b><br /> My code <?php // Make mysql connection below $mysql_conn = @mysql_connect("localhost", "****", "*****") or die("Could not connect to the Database, Please send us an e-mail in the contact section"); @mysql_select_db("*****", $mysql_conn) or die("DataBase does not exist"); $url = mysql_query("SELECT u_link FROM addurl") or die("Query error ".mysql_error()); $row = mysql_fetch_row($url); $page = file_get_contents($row[0]); // The HTML file will be put into a string called $page $page = file_get_contents($url); $sql = "insert into *** VALUES ($page)"; // Insert into Database; mysql_query($sql); ?> Quote Link to comment https://forums.phpfreaks.com/topic/83989-help-with-this-code/#findComment-427401 Share on other sites More sharing options...
trq Posted January 1, 2008 Share Posted January 1, 2008 Is that your actual code? This line.... $sql = "insert into *** VALUES ($page) is ill formed. Quote Link to comment https://forums.phpfreaks.com/topic/83989-help-with-this-code/#findComment-427402 Share on other sites More sharing options...
JJohnsenDK Posted January 1, 2008 Share Posted January 1, 2008 Your sql insert query isnt finished $sql = "insert into *** VALUES ($page)"; Quote Link to comment https://forums.phpfreaks.com/topic/83989-help-with-this-code/#findComment-427404 Share on other sites More sharing options...
Barand Posted January 1, 2008 Share Posted January 1, 2008 I've editted your code to use <?php instead of just <? Now you can tell instantly by the color coding that the string has a closing quote missing as all the following code is the same color as the string. Most parse errors are the result of carelessly omiting a closing quote or "}" or similar. Just check back over the previous few lines from where the error is reported. Quote Link to comment https://forums.phpfreaks.com/topic/83989-help-with-this-code/#findComment-427406 Share on other sites More sharing options...
anon Posted January 1, 2008 Author Share Posted January 1, 2008 Ok, its better, but Warning: file_get_contents() expects parameter 1 to be string, resource given in /home/***/public_html/****/thespider.php on line 13 wtf Quote Link to comment https://forums.phpfreaks.com/topic/83989-help-with-this-code/#findComment-427412 Share on other sites More sharing options...
Barand Posted January 1, 2008 Share Posted January 1, 2008 Have you still got file_get_contents($url)? Quote Link to comment https://forums.phpfreaks.com/topic/83989-help-with-this-code/#findComment-427414 Share on other sites More sharing options...
anon Posted January 1, 2008 Author Share Posted January 1, 2008 yes ...... this is what it is now though. $url = mysql_query("SELECT u_link FROM addurl") or die("Query error ".mysql_error()); $row = mysql_fetch_row($url); $page = file_get_contents($row[0]); // The HTML file will be put into a string called $page $page = file_get_contents($url); Quote Link to comment https://forums.phpfreaks.com/topic/83989-help-with-this-code/#findComment-427416 Share on other sites More sharing options...
Barand Posted January 1, 2008 Share Posted January 1, 2008 I give up. If you won't read the replies, why ask the questions? Quote Link to comment https://forums.phpfreaks.com/topic/83989-help-with-this-code/#findComment-427417 Share on other sites More sharing options...
anon Posted January 1, 2008 Author Share Posted January 1, 2008 Exactly as it says on the tin. $url needs to be a string (filename or variable containing a filename) Your $url is a resource handle to the results of the query. Ok. What exactly do you mean? Quote Link to comment https://forums.phpfreaks.com/topic/83989-help-with-this-code/#findComment-427419 Share on other sites More sharing options...
mrdamien Posted January 1, 2008 Share Posted January 1, 2008 yes ...... this is what it is now though. $url = mysql_query("SELECT u_link FROM addurl") or die("Query error ".mysql_error()); $row = mysql_fetch_row($url); $page = file_get_contents($row[0]); // The HTML file will be put into a string called $page $page = file_get_contents($url); Think about this. $url is a mysql ressource $row becomes an array containing the first row from your query $page becomes the file_contents of what ever $row[0] is $page is then re-assigned to what? Not the right thing. $page = file_get_contents($url); Is wrong. Get rid of it. Quote Link to comment https://forums.phpfreaks.com/topic/83989-help-with-this-code/#findComment-427613 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.