The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 18, 2019, 01:05:25 PM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: Trying to Pass Variable to create new Database  (Read 1988 times)
Politik
Rookie
**
Offline Offline

Posts: 11


View Profile
« on: August 27, 2007, 12:37:07 PM »

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?

Code:
<?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(36));
    
//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]."\n";
$kw  = urldecode(trim($keyword));
$kw      str_replace' '''$kw );

// Connect to Database
$con=mysql_connect ("localhost""UserName""Password"
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);
}
}
}
}


?>

Logged

No links in signatures please
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #1 on: August 27, 2007, 01:35:56 PM »

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:

Code:
<?php
$link 
mysql_connect("localhost""mysql_user""mysql_password");

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

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


/p
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
Politik
Rookie
**
Offline Offline

Posts: 11


View Profile
« Reply #2 on: August 27, 2007, 01:50:17 PM »

Thanks Perk! You the man!!
Logged

No links in signatures please
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #3 on: August 27, 2007, 02:03:19 PM »

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... Wink

/p
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!