Hi i have the below script but i get an error if a row is blank ie a return in the csv file at the end i need to somehow tell it to skip the rows that have nothing on them:
Code: <?php
// define table name and csv file location and name
$supp_id = "15";
$pricecode = "6";
$csvupload = "../ccd/Catalogue_ZZMILGAT.csv";
// create DB connection
$host = "localhost";
$user = "user";
$pass = "pass";
$mydb = "db";
$table = "table";
$db = mssql_connect($host,$user,$pass);
mssql_select_db($mydb);
// delete all old data
$sql2 = "DELETE FROM ".$table." WHERE supp_id = ".$supp_id."";
mssql_query($sql2) or die("Failed to insert to db ");
// Define DB mapping (Fill in rest of the mapping in order of appearance in CSV)
$fields = array(
"manufacturer",
"ignore",
"manf_part_no",
"supp_part_no",
"description",
"rrp",
"cost_price",
"avail_qty");
// Open the CSV file
$handle = fopen($csvupload, "r") or die("Unable to open $csvupload for reading");
// Get each row's values to an array
$i = 1;
// define tab delimited or comma
while (($data = fgetcsv($handle, 512, ",")) !== FALSE) {
// First row's headers and not included, otherwise row field count must match wanted field count
if(count($data)==count($fields) && $i!=1){
$rows[] = $data;
}
elseif(count($data)!=count($fields)) {
die("Erroneus CSV file: incorrect field count on row $i");
}
$i++;
}
// Close file handle
fclose($handle);
// Create SQL
if(count($rows)==0) die("No rows found in user file");
// Remove last comma
foreach($rows as $i => $row){
$sql = "INSERT INTO ".$table." (";
foreach($fields as $field)
if($field!="ignore")
$sql .= "$field,";
$sql = substr($sql,0,-1).",supp_id, date_added, PriceCode) VALUES ";
$sql .= "(";
foreach($row as $j => $value){
if($fields[$j]!="ignore"){
if(empty($value))
$value = "0";
// Quote strings, try to remove existing quotes
elseif(!is_numeric($value))
$value = str_replace("'","",$value);
$value = str_replace(""","",$value);
$sql .= "'$value',";
}
}
$sql = substr($sql,0,-1).",'".$supp_id."', getdate(),'".$pricecode."')"; // Remove last comma
//echo "SQL became: $sql";
mssql_query($sql) or die("Failed to insert to db ");
}
?>
UPLOAD IMAGES NOT WORKING!
Hi there i have a upload script in which it uploads the picture to a folder than creates two thumbnails in different folders however it is uploading the image and saving it in the folder /photos/ then
MySQL issue
I am taking sentences through a form on page. Then checking some condition and trying to insert them in database. I have issues while inserting...foreach ($sentences as $final) {......else {
Parse Error
Hi Guys,I have a function in my class which returns a string link variable. The problem is it keeps giving me a parse error. See code below followed by error message:Code: function
Multidimensional $_POST
HelloHow to get a single array from array of array (2 - dimension).For example I have a form:Line number On/Off | Expand/Contract <input type="text"
ECC6 - Single sign-on
We are in the process of upgrading to ECC 6 which will support single sign on with user passwords aligned by our active directory to the same as those used to access the Network. My query is that we
Not capturing all the information we require in the form.......
Hi Guys,I was wondering if you would share some more of your knowledge today, I'm hoping it will be quite a simple answer for you but one that is boggling us here! ;-)We have an html form that users
Why will this program not run if the variables are not global?
Hey guys I have a kind of perplexing situation that is probably simple, but I can't seem to understand something. I have this code here that is basically a program that solves all 92 eight queens
Including calander to page - will not show other months than current??
im trying to add an existaing calander onto a profile page by using Code: <?php include "diary/cal_show.php";?>which looks like this...But when i hit either arrows to move on
Database 'Validation'
Hi everyone,I'm trying to validate the password entered by the user with the password in the database. I've worked out that it checks the username fine (if the username doesn't exist it displays an
Read from a text file after a specific word
Hi all. I have a text file that looks like the one below. I know how to open the text file but I need to get the php pointer to take a value suck as $username. Once it finds $username, i need it to