Link to home
Start Free TrialLog in
Avatar of flow79
flow79Flag for United States of America

asked on

PHP/MySQL INSERT, tab delimited file

hello all,

I have the following code and it seems right to me, but it isnt actually performing the insert.  any ideas?

CODE
------------------------

<?  
$server = mysql_connect('localhost', 'root') or die(mysql_error());
mysql_select_db ('paper') or die (mysql_error());

$readfile = file("customers.txt");

for ($k=0; $k<=count($readfile)-1; $k++) {
    $fields = split("\t",$readfile[$k]);
    //echo("$fields[0] and $fields[1] and $fields[3] and $fields[4] and $fields[5] and $fields[6] and $fields[7] and $fields[8] and $fields[9] and $fields[10] and $fields[11] and $fields[12] and $fields[13]<br>");
            
            $query = "INSERT INTO customers VALUES ('$fields[0]','$fields[1]','$fields[2]','$fields[3]','$fields[4]','$fields[5]','$fields[6]','$fields[7]','$fields[8]','$fields[9]','$fields[10]','$fields[11]','$fields[12]','$fields[13]')";
            //echo $query;
            mysql_query($query);
            mysql_close();

            die(mysql_error());
}
?>

---------------------------
END CODE
Avatar of Roonaan
Roonaan
Flag of Netherlands image

Try: mysql_query($query) or die(mysql_error());

-r-
ASKER CERTIFIED SOLUTION
Avatar of sdmdj
sdmdj

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sdmdj
sdmdj

Oops, change:

@mysql_close() or die(mysql_error());

to:

@mysql_close($server) or die(mysql_error());

To ensure it closes the connection we created :-)