How to check duplicate and upload the new data when I use PHP to upload the CSV file into MySQL database


I have a CSV file which have ten column:




ID, fromDate, endDate, address, price1, price2, column1, column2,
column3, column4




but I just want to insert the first six columns into the MySQL
database, and most important, if there exist a tuple in the database
that the attribute(ID, fromDate, endDate, address) are the same, We
defined that the two rows are identify.



for example:
there exist a tuple in the database:




(1000, 2014-11-21, 2014-11-23, new york, 100, 200)




and Now, in the CSV file, there exists a row:




(1000, 2014-11-21, 2014-11-23, new york, 150, 250)




We defined that the two tuple are the same. So now we should update
the data in the database by the new data in the CSV file.



which means, delete the tuple




(1000, 2014-11-21, 2014-11-23, new york, 100, 200)




and insert the new tuple:




(1000, 2014-11-21, 2014-11-23, new york, 150, 250)




How to do this?



how to check for the duplicate when insert the data from CSV into
database, and once found a duplicate row, how to replace it?

I have a CSV file which have ten column:




ID, fromDate, endDate, address, price1, price2, column1, column2,
column3, column4




but I just want to insert the first six columns into the MySQL
database, and most important, if there exist a tuple in the database
that the attribute(ID, fromDate, endDate, address) are the same, We
defined that the two rows are identify.



for example:
there exist a tuple in the database:




(1000, 2014-11-21, 2014-11-23, new york, 100, 200)




and Now, in the CSV file, there exists a row:




(1000, 2014-11-21, 2014-11-23, new york, 150, 250)




We defined that the two tuple are the same. So now we should update
the data in the database by the new data in the CSV file.



which means, delete the tuple




(1000, 2014-11-21, 2014-11-23, new york, 100, 200)




and insert the new tuple:




(1000, 2014-11-21, 2014-11-23, new york, 150, 250)




How to do this?



how to check for the duplicate when insert the data from CSV into
database, and once found a duplicate row, how to replace it?

Web Development

I am trying to save images in my database from HTML form. I have
written PHP code to accomplish this task. The program is not
generating any error message, but also not inserting image data in
MySQL database. Kindly check it.
Here i am sharing a excerpt from my code.



        /*-------------------
IMAGE QUERY
---------------*/


$file =$_FILES['image']['tmp_name'];
if(!isset($file))
{
echo 'Please select an Image';
}
else
{
$image_check = getimagesize($_FILES['image']['tmp_name']);
if($image_check==false)
{
echo 'Not a Valid Image';
}
else
{
$image = file_get_contents ($_FILES['image']['tmp_name']);
$image_name = $_FILES['image']['name'];
if ($image_query = mysql_query ("insert into product_images
values (1,'$image_name',$image )"))
{
echo $current_id;
//echo 'Successfull';
}
else
{
echo mysql_error();
}
}
}
/*-----------------
IMAGE QUERY END
---------------------*/

<form action='insert_product.php' method='POST'
enctype='multipart/form-data' ></br>
File : <input type='file' name= 'image' >
</form>



Error Message
You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near '' at line 1


Web Development

I am trying for upload data from excel sheet to database using php.
I cant upload full data from excel sheet to database.I can upload only
10 data from excel to database.My excel sheet contain 20 data.But only
upload 10 numbers.The array $allDataInSheet contain only 10 values.
I refered these href="http://www.discussdesk.com/import-excel-file-data-in-mysql-database-using-PHP.htm"
rel="nofollow">http://www.discussdesk.com/import-excel-file-data-in-mysql-database-using-PHP.htm.



My code is given below.



main.php

<form action="<?php echo $_SERVER["PHP_SELF"]; ?>"
method="post" enctype="multipart/form-data">
<input type="file" name="file" id="file" />
<input type="button" name="submit" onClick="file_up()"/>
</form>
<srcipt>

function file_up()
{
var file=$('#file').val();
var cell=$('#cell').val();
$.ajax({
type: "POST",
url: 'ajx_upload.php',
data:'file='+file + '&cell=' + cell,
success: function(msg)
{
$("#upload_show").html(msg);
}
});
}
</script>


ajx_upload.php



   <?php
error_reporting(0);
$uploadedStatus = 0;
$cell=$_POST['cell'];
$file1=$_POST['file'];
$file1 = str_replace("\", "\", $file1);
$file1 = explode("\",$file1);
$file=$file1[2];

if (file_exists($file)) {
unlink($file);
}
$storagename = "discussdesk.xlsx";
move_uploaded_file($file, $storagename);
$uploadedStatus = 1;


if($uploadedStatus==1)
{
define ("DB_HOST", "localhost"); // set database host
define ("DB_USER", "root"); // set database user
define ("DB_PASS",""); // set database password
define ("DB_NAME","excel"); // set database name

$link = @mysql_connect(DB_HOST, DB_USER, DB_PASS) or
die("Couldn't make connection.");
$db = mysql_select_db(DB_NAME, $link) or die("Couldn't select
database");

$databasetable = "first";

set_include_path(get_include_path() . PATH_SEPARATOR .
'Classes/');
include 'PHPExcel/IOFactory.php';

// This is the file path to be uploaded.
$inputFileName = 'discussdesk.xlsx';

try {
$objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
} catch(Exception $e) {
die('Error loading file "'.
pathinfo($inputFileName,PATHINFO_BASENAME).'":
'.$e->getMessage());
}

$allDataInSheet =
$objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
$arrayCount = count($allDataInSheet);
// Here get total count of row in that Excel sheet
//print_r($allDataInSheet);
for($i=2;$i<=$arrayCount;$i++)
{
$userName = trim($allDataInSheet[$i]["A"]);
$userMobile = trim($allDataInSheet[$i]["B"]);
$query = "SELECT name FROM first WHERE name = '".$userName."'
and email = '".$userMobile."'";
$sql = mysql_query($query);
$recResult = mysql_fetch_array($sql);
$existName = $recResult["name"];
if($existName=="")
{
$insertTable= mysql_query("insert into
first (name, email) values('".$userName."',
'".$userMobile."');");
}
}
?>
Web Development

I want to upload a very large csv file into database,i.e, the size
of the csv file will be more than 1 GB. I want to upload all data from
csv file to mysql table as quick as possible. Please suggest me tha is
it possible or not?



And i want to use JQuery/Ajax for doing this job?

Web Development

I'm working on my CMS website and I want to make an Image upload
feature aswell and after submiting the file or imamge and the image
name I want It to be stored in my Database table instead of a folder
the table Is a long-blob I tried following a tutorial but It does not
work for me Here's my code for submiting all of the data including the
image:



<?php

if (isset($_POST['submit'])) {

$id = $_POST['postID'];
$title = $_POST['postTitle'];
$image = $_POST['postImage'];
$date = $_POST['postDate'];
$content = $_POST['postCont'];
$sum = $_POST['postSum'];
$key = $_POST['postKey'];
$num = $_POST['postNum'];

$id = mysql_real_escape_string($id);
$title = mysql_real_escape_string($title);
$image = mysql_real_escape_string($image);
$date = mysql_real_escape_string($date);
$content = mysql_real_escape_string($content);
$sum = mysql_real_escape_string($sum);
$key = mysql_real_escape_string($key);
$num = mysql_real_escape_string($num);

mysql_query("INSERT INTO posts
(postID,postTitle,postImage,postDate,postCont,postSum,postKey,postNum)
VALUES
('$id','$title','$image','$date','$content','$sum','$key','$num')")or
die(mysql_error());
$_SESSION['success'] = 'You have successfully Added a new post!';

}

?>


Please show me how to make a file uploader. Thank you!

Web Development

Here's the plugin: href="https://github.com/blueimp/jQuery-File-Upload">https://github.com/blueimp/jQuery-File-Upload



I'm having a problem getting the response I want from the plugin
after uploading a file.



On the page with the plugin, I have the following



$('#fileupload').fileupload(
'option',
{
'maxNumberOfFiles' :1,
'url' : '/admin/upload_handler.php'
}
);


In upload_handler.php I successfully retrieve the
uploaded files from $_FILES and do stuff, then send a response back in
JSON. I've confirmed using Firebug that the response is in the proper
format:



[ 
{
"url" : "image_url",
"thumbnail_url" : "image_th_url",
"delete_url" : "test",
"delete_type" : "DELETE",
"name" : "foobar.jpg",
"size" : 7419
}
]


But the callback can't find the files array, and I get the error:
'Empty file upload result'. I feel like I'm missing something crucial
here--I can't find anything in the docs, forums, or Stack Overflow. I
appreciate any help.

Web Development

- Technology - Languages
+ Webmasters
+ Development
+ Development Tools
+ Internet
+ Mobile Programming
+ Linux
+ Unix
+ Apple
+ Ubuntu
+ Mobile & Tablets
+ Databases
+ Android
+ Network & Servers
+ Operating Systems
+ Coding
+ Design Software
+ Web Development
+ Game Development
+ Access
+ Excel
+ Web Design
+ Web Hosting
+ Web Site Reviews
+ Domain Name
+ Information Security
+ Software
+ Computers
+ Electronics
+ Hardware
+ Windows
+ PHP
+ ASP/ASP.Net
+ C/C++/C#
+ VB/VB.Net
+ JAVA
+ Javascript
+ Programming
Privacy Policy - Copyrights Notice - Feedback - Report Violation 2018 © BigHow