Search Webmaster Help and Solution

inserting data into a table from a txt file

I want to update products every day from a text file.

This script should help me to do that but it does not.

Would anybody help me to get this right?


PHP Code: $array=file(/mypath/file.txt);

$rCount=0;

    foreach($array as $value)
            {

        mysql_query(INSERT INTO tempProducts VALUES (.trim($value).) or die(mysql_error());
        $rCount++;

        }

$numRecords=mysql_result(mysql_query(SELECT COUNT(PCode) as Num FROM tempProducts),0);

if($numRecords==$rCount)
    {

$sql = TRUNCATE TABLE products;

mysql_query($sql) or die(mysql_error());

$putProducts = INSERT INTO products SELECT * FROM tempProducts;

mysql_query($putProducts) or die(mysql_error());

}
Kind regards,
laanes I want to update products every day from a text file.

This script should help me to do that but it does not.

Would anybody help me to get this right?


PHP Code: $array=file(/mypath/file.txt);

$rCount=0;

    foreach($array as $value)
            {

        mysql_query(INSERT INTO tempProducts VALUES (.trim($value).) or die(mysql_error());
        $rCount++;

        }

$numRecords=mysql_result(mysql_query(SELECT COUNT(PCode) as Num FROM tempProducts),0);

if($numRecords==$rCount)
    {

$sql = TRUNCATE TABLE products;

mysql_query($sql) or die(mysql_error());

$putProducts = INSERT INTO products SELECT * FROM tempProducts;

mysql_query($putProducts) or die(mysql_error());

}
Kind regards,
laanes

View Complete Thread with Replies

Related Items

Query failed: connection to localhost:3354 failed (errno=111, msg=Connection refused).