Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am running Raspbian on a Pi and installed Apache, Php5 and sqlite I am inserting some values into sqlite table through php web page, but I am not able to insert though I can upload the file

Following is the Simple Following PHP code.

Note:- Same works on WAMP smoothly. Please suggest the solution.

Thanks in Advance.

 <?php 

 if (!empty($_POST['btnUploadAlbum'])) 
    {
   $dir = 'sqlite:test.sqlite';
   //echo $userName . $emailId . $msg;
   //   echo "success opens";
    $db = new PDO($dir) or die("cannot open the database");
   echo "DB opens";
    $dirName='Albums/Album'; 
  if (!file_exists($dirName)) {
                    mkdir($dirName, 777,true);
               }
    if(!empty($_POST['AlbumName']))
    {
    $dirName=$dirName . $_POST['AlbumName'];
     if (!file_exists($dirName)) {
                    mkdir($dirName, 777,true);
               }
      if (isset($_FILES['fileuploadSong']['name'])) {
        $fileName = $_FILES['fileuploadSong']['name'];
        if(strpos($fileName,'.mp3') or strpos($fileName,'.mp4'))
        {
            $dirName = $dirName."/". basename($fileName);

       // echo $dirName;

            if (move_uploaded_file($_FILES['fileuploadSong']['tmp_name'], $dirName)) 
            {
                echo "in 1";

                $statement = "INSERT INTO AlbumFiles (SongName,SongPath) values ('$fileName','$dirName')";
                echo $statement;
                $db->exec($statement) or die("not executed");

                echo '<script language="javascript">';
                echo 'alert("'.$fileName.' uploaded successfully sent");';
                echo '</script>';
                echo "in 2 executed";
            }
        }
         else
           {
            echo '<script language="javascript">';
                echo 'alert("Please upload Mp3/Mp4 files!")';
                echo '</script>';
         }

     }

    }
 }
?>
share|improve this question
    
And what happens? –  CL. Sep 2 '14 at 12:50
    
Insert Statement dose not works and no value is inserted in table, but when same run on CLI as sudo php file.php it works but needs sudo access –  slashRahul Sep 2 '14 at 12:55
    
And what about that die("not executed")? –  CL. Sep 2 '14 at 13:08
    
it is just for printing if it is executed or not successfully –  slashRahul Sep 2 '14 at 13:42
    
And does it print, or not? –  CL. Sep 2 '14 at 13:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.