Hey there everyone.
Years ago I used to be active on Pixel2Life. Seems they have died down. I got out of web coding for quite a few years since I have been in the Army.
I have had a code on a website that uploaded a Excel CSV file into a database. I know it shouldn't be a complicated task, but with this file different things get uploaded depending on what the values are on the file.
Now I am assuming when my Hosting company upgraded to PHP 5 I started getting these errors.
I would like to know how to get rid of those. As well as since the original code I have added a section. I added one more field in the CSV file that is the Original Price. Now in the code I will post I have that section called $pd_spc_price. What that section is suppose to do is if there is a value in the last field in the CSV file it will upload that price or it will upload the previous price that is uploaded earlier. If that make sense. I will post the code and a sample of the CSV file.
mysql_query("DELETE FROM tbl_product") or die("Could not delete old information from database");
$file = file_get_contents($_FILES["phile"]["tmp_name"]);
$file_line = explode("\n",$file);
$j = "0";
foreach($file_line as $line) {
$line_data = explode('","', $line);
if($j>"0") {
$splititupsomemore = explode(',', $line_data[1]);
// $pd_id
$pd_name = addslashes(substr($line_data[0], 1));
if(substr($pd_name, 0, 1)=="z"||substr($pd_name, 0, 1)=="Z") {
$cat_id = "1";
} else {
$cat_id = "18";
}
$pd_description = addslashes($splititupsomemore[0]);
$pd_price = str_replace("\r", "", addslashes($splititupsomemore[1]));
$pd_spc = addslashes(substr($splititupsomemore[2], 1));
if(substr($pd_spc, 0, 1)=="Y"||substr($pd_spc, 0, 1)=="y") {
$spc_id = "1";
} else {
$spc_id = "0";
}
$pd_spc_price = addslashes(substr($splititupsomemore[3], 1));
if($pd_spc_price == TRUE){
$spc_price = $pd_spc_price;
} else {
$spc_price = $pd_price;
}
// $pd_qty
// $pd_image
// $pd_thumbnail
$pd_date = date("Y-m-d G:i:s");
// $pd_last_update
$query = "INSERT INTO tbl_product VALUES('', '$cat_id', '$pd_name', '$pd_description', '$pd_price', '', '', '', '$pd_date', '', '$spc_id', '$spc_price')";
mysql_query($query) or die($query);
}
$j++;
}
echo '<h3><p>The pricelist was updated on '.$pd_date.'. If this is not the current day and time the upload did not work.<br /><a href="index.php">Go Back</a></p></h3>';
This is the CSV file I have
As you can see the two middle lines have a price on the very end. Not all will have that and I am having an issue figuring that part of the code out.
Any help would be great. I haven't been able to get myself fully back into coding. Plus a lot has changed in the last 5 years.
Thanks!