I have craated one web form to upload csv sheet to mysql database, the primary key is "sample name" in database, i am trying to avoid duplication of "samplename" before uploading to database. my question is , Is it possible to do so?
<html>
<body>
<form action="dform.php" method="post" enctype="multipart/form-data">
<input name="csv" type="file" id="csv" accept=".xls"/> <br /> <br />
<input type="submit" name="Submit" value="UPDATE" />
</form>
</body>
</html>
above i saved as "dform.html"
<?php
if (!$_POST)
{
?>
<?php
} else {
$connect = new mysqli("localhost", "root", "", "ProcessTrackingSystem");
if ($_FILES[csv][size] > 0) {
//get the csv file
$file = $_FILES[csv][tmp_name];
$handle = fopen($file, "r");
$i = 0;
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
if ($i > 0) {
$import = ("INSERT INTO ProcessTrackingSystem.ProcessDetails VALUES('" . implode("','", $data) . "');");
$connect->query($import);
}
$i++;
}
fclose($handle);
echo "THANKS FOR UPLOADING"."<br>"."<br>";
echo "Hit Back Button to UPLOAD MORE Data Sheets";
}
}
?>
above code i saved as "dform.php".
any doughts and clarifications regarding above asked question are welcome.