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
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
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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.