Hi all, I hope someone can help me with the following. I have a script that reads a txt file and displays the correct values. I only want to add it to the database now, but I can't manage this. below the script

<?php 
include '../includes/connect.php';

    if(!$conn)
{
    die(mysqli_error());
}


    $fd = fopen ("import/8.txt", "r");

while (!feof ($fd))
{
 $buffer1 = fgets($fd, 4096);
 if (substr($buffer1,0,7)=='#EXTINF')
 {
  $buffer = fgets($fd, 4096);
  $buffer = str_replace("'","`",$buffer);
  $array=explode('\\',$buffer);
  $count = count($array);

  list($artiest,$titel) = explode(' - ',$array[$count-1]);

  if (strlen($titel)==0)
  {print("$artiest <br>");
   list($artiest,$titel) = explode('- ',$array[$count-1]);
   if (strlen($titel)==0)
   {print("$artiest <br>");
    list($artiest,$titel) = explode(' -',$array[$count-1]);
    if (strlen($titel)==0)
    {
     print("$artiest <br>");
     list($artiest,$titel) = explode('-',$array[$count-1]);
     if (strlen($titel)==0)
     {
      $buffer = str_replace("'","`",$buffer1);
      $pos=strpos($buffer,',');
      $tekst = substr($buffer,$pos+1);
      list($artiest,$titel) = explode(' - ',$tekst);
      if (strlen($titel)==0)
      {
       list($artiest,$titel) = explode('- ',$tekst);
       if (strlen($titel)==0)
       {
        list($artiest,$titel) = explode(' -',$tekst);
        if (strlen($titel)==0)
        {
         list($artiest,$titel) = explode('-',$tekst);
         if (strlen($titel)==0)
          print("$artiest <br>");

            $sql= "INSERT INTO mp3 (id_dj,artiest,titel) VALUES ('8','$artiest','$titel')";



    }



}

        }

       }
      }
     }

    }

   }

  }


echo "import mp3's klaar";







?>

What is inside the included/connect.php file? Does the database successfully connect? Do you just need help working out this particular SQL statement?

I would also say always, always, always escape anything you use in a database query so you won’t introduce an SQL injection bug. Look into mysql_real_escape().

For MySQL database I use delphi mysql connection tool. Maybe you'll find some useful features and solve your problem too.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.