OK folks, here’s a fun one for you.
So our back office system has all the cruise fares in it and we’ve made a nice little script that allows the back office system’s export of the fares to import into the website.
It’s a neat script, except… the back office system exports the cruise code e.g. P210 and the website’s database has a fares table which contains each fare as record, connected to the relevant cruise by a ‘cruise_id’
So the cruise table is something like this
id title code departs….. etc etc
and the fare table is like this
id cruise_id fare offer… etc etc
Works great on the site, but the back office export doesn’t know the unique id of the cruise on the website.
So is it possible, after we have uploaded the csv file, before it inserts, to look up the cruise_id from the cruises table using the code, and use that in the insert query ?
Here’s the upload script so far
<?php
require_once('includes/connection.php');
if(isset($_POST['submit']))
{
$filename=$_FILES['filename']['tmp_name'];
$handle = fopen("$filename", "r");
while (($data = fgetcsv($handle, 100000, ",")) !== FALSE)
{
$import="INSERT into fares_usa(cruise_id, active, type, category, placement, deck, fare, offered, status, sortorder)
values('".mysql_real_escape_string($data[0])."',
'".mysql_real_escape_string($data[1])."',
'".mysql_real_escape_string($data[2])."',
'".mysql_real_escape_string($data[3])."',
'".mysql_real_escape_string($data[4])."',
'".mysql_real_escape_string($data[5])."',
'".mysql_real_escape_string($data[6])."',
'".mysql_real_escape_string($data[7])."',
'".mysql_real_escape_string($data[8])."',
'".mysql_real_escape_string($data[9])."')";
mysql_query($import, $connection) or die(mysql_error());
}
fclose($handle);
print "Import done";
}
else
{
print "<form enctype='multipart/form-data' action='fileupload.php' method='POST'>";
print "Select file to import:";
print "<input type='file' name='filename' size='20'>";
print "<input type='submit' name='submit' value='submit'></form>";
}
?>
I hope I have explained it ok…
Rich 🙂
fixed it… here’s the code