Ive added this check in other php scripts be for but its not working for some reason now

//Database Connection
$connect = mysql_connect("localhost", "root", "") or die ("Couldnt connect");
$db = mysql_select_db("photos", $connect) or die ("Couldnt open Database");
$check_query = mysql_query("SELECT * FROM Photos WHERE PhotoName='$entry' AND PhotoLocation='$partialPath' ");
$partialPath = addslashes($partialPath);
$entry = addslashes($entry);
$thumbnail = addslashes($thumbnail);

if (mysql_num_rows($check_query) == 0) {
//Insert SQL Statment
$sql = "INSERT INTO Photos SET PhotoName = '$entry', PhotoLocation = '$partialPath', PhotoThumbnail = '$thumbnail'";
$sql_result = mysql_query($sql, $connect) or die ("Could not insert user into database");
echo "<b>Merging:</b> <i>".$partialPath."\\".$entry."</i><br>"; 
} else {
echo "<b>Already Merged:</b> <i>".$partialPath."\\".$entry."</i><br>"; 
}

im checking the database for duplicates
if (mysql_num_rows($check_query) == 0) {

now if it returns 0 then go ahead and echo out merigng else echo out already merged

now no matter what I do, it always says merging even though there are records of the same thing in the database already and it will add them making duplicates in the database.. hope this makes sense

    On the upper query you dont have your $connect.

    $check_query = mysql_query("SELECT * FROM Photos WHERE PhotoName='$entry' AND PhotoLocation='$partialPath' ",$connect);

      Are variables $entry and $partialPath set correctly?
      Insert a print to check their values

      print "entry:$entry partialPath:$partialPath<br>\n";
      

        here is the whole script

        <?
        //*********************************************************\\
        // Name: Merge Script
        // Programmer: Derrick Rose
        // Date: Dec 16, 2002
        // Summery: Thumbnail/Indexing Script
        //**********************************************************\\
        
        require('cfg.php');
        function getDirList ($dirName) { 
        $d = dir($dirName); 
        while($entry = $d->read()) { 
        if ($entry != "." && $entry != ".." && $entry != "index.php" && $entry != "cfg.php") { 
        if (is_dir($dirName."\\".$entry)) { 
        getDirList($dirName."\\".$entry); 
        } else { 
        //**********************************************************\\
        // Edit the BasePath to the directory path of the scripts   \\
        //**********************************************************\\
        $basePath = "C:\\Inetpub\\wwwroot\\photolab\\"; 
        //Start code
        $partialPath = substr($dirName,strlen($basePath), strlen($dirName) - strlen($basePath)); 
        $thumbnail = "thumbnail\\".$partialPath."\\thumb_".$entry;
        $partialPath2 = "images\\".$partialPath;
        $partialPath2 = addslashes($partialPath2);
        
        //Database Connection
        $connect = mysql_connect("localhost", "root", "") or die ("Couldnt connect");
        $db = mysql_select_db("photos", $connect) or die ("Couldnt open Database");
        $check_query = mysql_query("SELECT * FROM Photos WHERE PhotoName='$entry' AND PhotoLocation='$partialPath' ");
        $partialPath = addslashes($partialPath);
        $entry = addslashes($entry);
        $thumbnail = addslashes($thumbnail);
        
        if (mysql_num_rows($check_query) == 0) {
        //Insert SQL Statment
        $sql = "INSERT INTO Photos SET PhotoName = '$entry', PhotoLocation = '$partialPath', PhotoThumbnail = '$thumbnail'";
        $sql_result = mysql_query($sql, $connect) or die ("Could not insert user into database");
        echo "<b>Merging:</b> <i>".$partialPath."\\".$entry."</i><br>"; 
        } else {
        echo "<b>Already Merged:</b> <i>".$partialPath."\\".$entry."</i><br>"; 
        }
        } 
        } 
        } 
        mysql_close($connect);
        $d->close(); 
        }
        getDirList("$image_location"); 
        ?>
        

        sorry have to use code or else the \ wont show up

          Originally posted by Sore
          On the upper query you dont have your $connect.


          $check_query = mysql_query("SELECT * FROM Photos WHERE PhotoName='$entry' AND PhotoLocation='$partialPath' ",$connect);

          [/B]

          oops your right thats what it was, thank you 🙂

          man to much coding... need a break

            Please add an or-statement to following line

            check_query = mysql_query("SELECT * FROM Photos WHERE PhotoName='$entry' AND PhotoLocation='$partialPath'")
               or print "&gt;&gt;&gt; MySQL-Error: ".mysql_errno()." -&gt; ".mysql_error()."<br>\n";
            

            Do you get an error message?

              Originally posted by hand
              Please add an or-statement to following line

              check_query = mysql_query("SELECT * FROM Photos WHERE PhotoName='$entry' AND PhotoLocation='$partialPath'")
                 or print "&gt;&gt;&gt; MySQL-Error: ".mysql_errno()." -&gt; ".mysql_error()."<br>\n";
              

              Do you get an error message? [/B]

              thanx but I got it working 🙂

              $connect = mysql_connect($server, $user_name, $user_pass) or die ("Couldnt connect");
              $db = mysql_select_db($database, $connect) or die ("Couldnt open Database");
              $check_query = "SELECT * FROM Photos WHERE PhotoName='$entry' AND PhotoLocation='$partialPath'";
              $results = mysql_query($check_query, $connect); 
              
              if (mysql_num_rows($results) == 0) {
              //Insert SQL Statment
              $sql = "INSERT INTO Photos SET PhotoName = '$entry', PhotoLocation = '$partialPath', PhotoThumbnail = '$thumbnail'";
              $sql_result = mysql_query($sql, $connect) or die ("Could not insert user into database");
              echo "<b>Merging:</b> <i>".$partialPath."\\".$entry."</i><br>"; 
              } else {
              echo "<b>Already Merged:</b> <i>".$partialPath."\\".$entry."</i><br>"; 
              }
              

              I was never connecting and getting my records ehhe

                Write a Reply...