Politik

Hey Guys,

I am trying to pass a variable as a string to create a new SQL table in my script but it's not doing it. I am not getting any error messages and my script will save to a text file, but I can't get it to save to a database. Any Ideas?


<?

php

 
include ("snoopy.class.

php

 ");
// Identify the search term

$footprintsFile = 'footprints.txt';
$footprints = file($footprintsFile);


foreach ($footprints as $footprint) {

  $footprint = urlencode(trim($footprint));
  $query = "http://www.google.com/search?q=";
  $search = $query.$footprint;

  $keywordFile = "keywords.txt";
$keywords = file($keywordFile);

  foreach($keywords as $keyword) {

$keyword = urlencode(trim($keyword));

for ($i = 0; $i <=2; $i++) {

$target = $search."+".$keyword."&hl=en&start=".($i*10)."&sa=N&filter=0";

// Verify that there are not illegal characters in the urls
    $target = html_entity_decode($target);

    $snoopy = new Snoopy;

    sleep(rand(3, 6));
    //hit google
$page = $snoopy->fetch($target);
$page = $snoopy->results;//create an array to hold our links

//parse out the links we want
preg_match_all('/<a href="([^"]+)" class=l>(.*?)</a>/', $page, $output);



for ($x=0; $x<=(count($output[1])); $x++){

$stuff = $output[1][$x]." ";
$kw = urldecode(trim($keyword));
$kw      = str_replace( ' ', '', $kw );

// Connect to Database
$con=mysql_connect ("localhost", "UserName", "Password"Applause
or die
('Cannot connect to the database because:' . mysql_error());

// Create Database
mysql_query("CREATE DATABASE WordPressBlogs",$con);

// Create table in my_db database
mysql_select_db("WordPressBlogs", $con);
mysql_query("CREATE TABLE {'$kw'}
(
ID int NOT NULL AUTO_INCREMENT,
PRIMARY KEY(ID),
URL varchar(255)
)");

// Insert Info into Database
mysql_query("INSERT INTO {'$kw'} (URL)
VALUES ({'$stuff'})");

mysql_close($con);
}
}
}
}


?>

perkiset

Without reading your whole script, my first suggestion would be to do this:

error_reporting(E_ALL);

at the top so that every little warning and such will be spit back outatcha. Probably have better symptoms then.

I'd also use mysql_error to see what the response was. Here is the demo code for mysql_error from the

PHP

  dox:


<?

php

 
$link = mysql_connect("localhost", "mysql_user", "mysql_password");

mysql_select_db("nonexistentdb", $link);
echo mysql_errno($link) . ": " . mysql_error($link). " ";

mysql_select_db("kossu", $link);
mysql_query("SELECT * FROM nonexistenttable", $link);
echo mysql_errno($link) . ": " . mysql_error($link) . " ";
?>


/p

Politik

Thanks Perk! You the man!!

perkiset

Given the error that was posted over at the syndk8, the mysql_error would have caught it.

Good stuff to keep in the toolchest man... Applause

/p


Perkiset's Place Home   Politics @ Perkiset's