Forum Moderators: coopster

Message Too Old, No Replies

csv to mysql php script

         

jmbaruk

6:09 am on Jun 26, 2009 (gmt 0)

10+ Year Member



i got this code yesterday from this website since i thought it could assist me import data from a csv file to a mysql database... i did some modifications and now it queries like 45o records then returns the error "cannot query",the csv file has around 1500 entries.
could anyone look at the code and assist me please

--------------------------------------------------------------
<?php
//include(utsi_config.php);

$uinput=$_GET['uinput'];
$path="./serials";
$ext='csv';
$filename=($path.'/'.$uinput.'.'.$ext);

if (file_exists($filename))
{
function AddMerchant($name,$number,$outstanding,$duedate,$instalment)
{
global $db_host,$db_user,$db_pwd,$db_name;
$db_host = "localhost";
$db_user = "root";
$db_pwd = "";
$db_name = "sms_db";
mysql_connect($db_host, $db_user, $db_pwd);
mysql_select_db($db_name);
mysql_connect("$db_host","$db_user","$pdb_pwd")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="INSERT IGNORE INTO `outgoingsms` (`msisdn`, `message`, `timelog`, `status`, `sendoption`, `deleted`, `retries`) VALUES ('$number', 'Dear $name,your current arrears are $outstanding.your next instalment of $instalment is due on $duedate Please make arrngments to clear your dues', current_timestamp, '0', '1', '0', '0')";
mysql_query($sql) or die("cannot query");
}

$file=file_get_contents($filename);
$rows=explode("\n", $file);

foreach($rows as $row)
{
$items=explode(",", $row);
AddMerchant($items[0],$items[1],$items[2],$items[3],$items[4]);
echo "complete";
}
}
else
{
echo "wrong file!";
}

?>

jatar_k

1:34 pm on Jun 26, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld jmbaruk,

add a bit to your query line

mysql_query($sql) or die("<p>cannot query: $sql<br>" . mysql_error());

that will show you the query it was executing and the actual error from mysql. Take a look at that and see if it gives you an added hint as to what's going on.