Jump to content

Help with this code


anon

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/83989-help-with-this-code/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/83989-help-with-this-code/#findComment-427397
Share on other sites

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);

?>

Link to comment
https://forums.phpfreaks.com/topic/83989-help-with-this-code/#findComment-427401
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/83989-help-with-this-code/#findComment-427406
Share on other sites

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);

Link to comment
https://forums.phpfreaks.com/topic/83989-help-with-this-code/#findComment-427416
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/83989-help-with-this-code/#findComment-427613
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.