Jump to content

[SOLVED] using file_get_contents() with real websites


contra10

Recommended Posts

Hi im trying to build a crawler and right now im trying to get information from websites and save it in my db. right now im testing on my local host and was wondering if i can access live pages. I tried to copy a wikipedia website and i got this

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'text/javascript'>if (wgNotice != '') document.writeln(wgNotice);

i was wondering if im on the right track or loss... heres my coding

 

<?php
//This code runs if the form has been submitted
if (isset($_POST['submit'])) { 

$search = mysql_real_escape_string($_POST['search']);

$data = file_get_contents("$search");

// now we insert it into the database
$insert = "INSERT INTO `web` (`website`, `index`)
VALUES ('$search', '$data')";
$add_web = mysql_query($insert) or die (mysql_error());

echo "$data";
?>
sucess
<?php
}else{
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<h2><a href="#">Add a site</a></h2><br>
<input type="text" size="35" name="search"/><br>
<input type="submit" name="submit" />
</form>

 

btw it will work for pages in my local host

Try mysql_real_escape_string on the two variables before they go into mysql.  http://ca.php.net/mysql_real_escape_string.  You will need to watch out for exploits as well, but get it working first and then worry about that. 

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.