You are here:  » Inserting data in to MySQL database

Inserting data in to MySQL database

Submitted by baggagepin on Fri, 2010-04-23 13:15 in

Hi and thank you in advance for any help you can provide.

I am reading a CSV file which contains 400 records.

How can I populate my data table with the results.

My code so far is:

$filename = 'lhr.csv';
if (file_exists($filename)) {
function myRecordHandler($record)
$ArrDep = mysql_real_escape_string($record["ArrDep"]);
$Airline = mysql_real_escape_string($record["Airline"]);
$FltNo = mysql_real_escape_string($record["FltNo"]);
$Time = mysql_real_escape_string($record["Time"]);
$Est = mysql_real_escape_string($record["Est"]);
$City1 = mysql_real_escape_string($record["City1"]);
$City2 = mysql_real_escape_string($record["City2"]);
$Iata = mysql_real_escape_string($record["Iata"]);
$Stat = mysql_real_escape_string($record["Stat"]);
$Gate = mysql_real_escape_string($record["Gate"]);
$Term = mysql_real_escape_string($record["Term"]);
$Stand = mysql_real_escape_string($record["Stand"]);
$Date = mysql_real_escape_string($record["Date"]);
  $query = "INSERT INTO `fids` ( `ArrDep` ,`Airline `,`FltNo`,`Time`,`Est `,`City1`,`City2`,`Iata`,`Stat`,`Gate`,`Term`,`Stand`,`Date` )
    VALUES ('".$ArrDep ."','".$Airline."','".$FltNo."','".$Time."','".$Est."','".$City1 ."','".$City2 ."','".$Iata."','".$Stat ."','".$Gate."','".$Term."','".$cStand."','".$Date."')";
 $result = MYSQL_QUERY($query);

Again, many thanks,


Submitted by support on Fri, 2010-04-23 13:21

Hi Dereck,

Your code looks very close to being complete, so it is probably either a connection problem (I assume this all takes place within your Connections/con.php include), or the query being constructed is not compatible with your table.

Either way, the problem should be reveal with a call to mysql_error(), which will print details of the last problem that occurred within the MySQL library.

In your code, in place of:

 $result = MYSQL_QUERY($query);

...have a go with:

 $result = mysql_query($query);
 print mysql_error();

...and any problem should be displayed.

Hope this helps!