Directory listing to mysql

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ambriel25
    New Member
    • Apr 2008
    • 3

    Directory listing to mysql

    I followed a set of posts on this site on how to do this but being the noob that I am got stuck :)

    My code runs as follows:


    <?php
    $dbhost = '******';
    $dbuser = '******';
    $dbpass = '******';
    $conn = mysql_connect($ dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');

    $dbname = '******';
    mysql_select_db ($dbname);

    $fol = "./Imgs/images/";
    $dir = opendir ($fol);
    while (false !== ($file = readdir($dir))) {
    if (strpos($file, '.gif',1)||strp os($file, '.jpg',1) ) {
    // (This was just for testing) echo "<a href=\"".$fol." ".$file."\">".$ file."</a><br />";

    $query = 'INSERT INTO `******`.`***** *` (`id`, `pasta`, `nome`) VALUES (NULL, $fol, $file);';
    mysql_query($qu ery) or die('Error, insert query failed');
    }
    }
    ?>


    It gives me 'Error, insert query failed' and I assume it's because of the variables

    Can someone help?

    PS: The $fol variable exists because it will be eventualy replaced by form variable.

    Thanks in advance
  • nitinpatel1117
    New Member
    • Jun 2007
    • 111

    #2
    Think you may have the aspostrophes in the wrong place

    $query = "INSERT INTO ******.****** (id, pasta, nome) VALUES (NULL, '$fol', '$file');";

    try that.

    Comment

    • Markus
      Recognized Expert Expert
      • Jun 2007
      • 6092

      #3
      Originally posted by ambriel25
      I followed a set of posts on this site on how to do this but being the noob that I am got stuck :)

      My code runs as follows:


      <?php
      $dbhost = '******';
      $dbuser = '******';
      $dbpass = '******';
      $conn = mysql_connect($ dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');

      $dbname = '******';
      mysql_select_db ($dbname);

      $fol = "./Imgs/images/";
      $dir = opendir ($fol);
      while (false !== ($file = readdir($dir))) {
      if (strpos($file, '.gif',1)||strp os($file, '.jpg',1) ) {
      // (This was just for testing) echo "<a href=\"".$fol." ".$file."\">".$ file."</a><br />";

      $query = 'INSERT INTO `******`.`***** *` (`id`, `pasta`, `nome`) VALUES (NULL, $fol, $file);';
      mysql_query($qu ery) or die('Error, insert query failed');
      }
      }
      ?>


      It gives me 'Error, insert query failed' and I assume it's because of the variables

      Can someone help?

      PS: The $fol variable exists because it will be eventualy replaced by form variable.

      Thanks in advance
      Do not [b] your code use [code=xxx] to format it.
      If the #2 post doesnt help, try:
      [php]
      mysql_query($qu ery) or die('Error, insert query failed - ' . mysql_error());
      [/php]

      Comment

      • ambriel25
        New Member
        • Apr 2008
        • 3

        #4
        thanks, I'm such a noob the 1st one did it.

        Will use the code tag from now on

        Again thank you

        Comment

        • ambriel25
          New Member
          • Apr 2008
          • 3

          #5
          Again, is there a way to recursevly scan al the sub folders inside a main one for the same effect?

          Comment

          Working...