** I made some changes to correct and obvious error I had
New Code listed below ****
Thanks again for any assistance
I have created some code to do the following things and I have a few bugs in it that I will describe as I go.
What I am trying to accomplish is
1. read variables passed from a Form which contains the Database , Table name , and Data File for load,.
2. Check to see if table exists If so then drop it
3 Create new table
4 Load new Table with data file which is Pipe delimeted newline terminated
I think I have pieced together a somewhat close rendition to what I have described above but I am having problems with
(1) syntax around line 81 which is the Drop table $DB_NAME
and
(2) I think I may have a problem if the section that checks if the TB_name is returnd when the tables are listed has more than 1 table returned... not real sure about this.
I am Very new to this and thought I would ask now that I have pieced what I could together.
Any help with this would be greatly apreciated.
Thank You
Robert
Code: Select all
<?php
// Connect to database
include $_SERVER['DOCUMENT_ROOT']."/php/connectdor.php";
$sqlstep = mysql_list_tables($DB_NAME);
if (!$sqlstep) {
echo "Error, could not list tables\n";
echo 'MySQL Error code: ' . mysql_error();
exit;
}
// If DORLIST TABLE EXISTS Drop it
if(mysql_list_tables($DB_NAME) == $TB_NAME){
$sqlstop = Drop table '$TB_NAME'; }
$result = mysql_query($sqlstep);
if (!$result) {
echo("<p>Error performing query: $sqltep " . mysql_error() . "</p>");
exit();
}
echo "$DB_NAME.$TB_NAME dropped\n";
// If DORLIST Table does not exist create it
if(mysql_list_tables($DB_NAME) != $TB_NAME){
$sqlstop = CREATE TABLE '$TB_NAME'(
id int(6) NOT NULL auto_increment,
Title varchar(5) NOT NULL,
Last_Name varchar(25) NOT NULL,
First_Name varchar(15) NOT NULL,
Middle_Name varchar(10) NOT NULL,
DFD DATETIME NOT NULL,
DOB DATETIME NOT NULL,
DOD DATETIME NOT NULL,
Spouse varchar(15) NOT NULL,
Addr1 varchar(30) NOT NULL,
City varchar(20) NOT NULL,
State varchar(2) NOT NULL,
ZIP varchar(5) NOT NULL,
Phone varchar(20) NOT NULL,
PRIMARY KEY (id),UNIQUE id (id),KEY id_2 (id)
) }
$result = mysql_query( $sqlstep );
$sqlstep="LOAD DATA LOCAL INFILE '$Infile_name' INSERT INTO TABLE $TB_Name.$TB_NAME FIELDS TERMINATED BY '|' LINES TERMINATED BY '\n'";
$result = mysql_query($sqlstep);
if (!$result) {
echo("<p>Error performing query: $sqltep " . mysql_error() . "</p>");
exit();
}
echo (mysql_affected_rows() . " rows inserted into $DB_NAME.$TB_NAME \n\r");
mysql_close($db);
?>
?>