0

I tried it with if exists on sql but it says error.

if (isset($_POST['ReScan'])){
$dateien = 'dateien/';
$directoryscanarray = scandir($dateien);
print_r($directoryscanarray);

$arrlength = count($directoryscanarray);

for($x = 2; $x <  $arrlength; $x++) {
$foldername = $directoryscanarray[$x];
$sql = "INSERT INTO localfiles (foldername) VALUES ('$foldername')";

maybe:

WHERE NOT EXISTS SELECT foldername FROM localfiles WHERE name='$foldername'";
davejal
  • 6,009
  • 10
  • 39
  • 82

2 Answers2

1

You can make the foldername an unique key and use

INSERT INTO ... ON DUPLICATE KEY UPDATE ...

Where on duplicate key you would just say the key equals itself

http://dev.mysql.com/doc/refman/5.7/en/insert-on-duplicate.html

INSERT ... ON DUPLICATE KEY (do nothing)

Community
  • 1
  • 1
0

You could try this (not tested):

$sql = " INSERT INTO localfiles (foldername) VALUES ('$foldername') ON DUPLICATE KEY UPDATE field_1="value_1", field_2="value_2" WHERE foldername='$foldername'";
hherger
  • 1,660
  • 1
  • 10
  • 13