SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,107
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Post Help me on this error

    Hi, can you help me please i am having problem in uploading the video.the length of my video is 5.88mb and the format is .ogv,when i am going to upload this it will message like this.
    FAILED TO INSERTCannot add or update a child row: a foreign key constraint fails (`uploadmovie`.`tbl_mname`, CONSTRAINT `tbl_mname_ibfk_1` FOREIGN KEY (`mf_id`) REFERENCES `tbl_movie` (`id`))
    but when i am going to upload text file or some exe file like firefox,it will succesfully uploaded..i am confuse why it will not upload the movie.

    I also check in the firebug and this is the error..
    The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the page must to be declared in the document or in the transfer protocol.
    can you help me please.Thank you in advance.

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Are you trying to add a row to the table with a mf_id that doesn't exist in the table the foreign key points to?

  3. #3
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,107
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    Are you trying to add a row to the table with a mf_id that doesn't exist in the table the foreign key points to?
    Hi, Thank you for the reply,This is how i created my table

    but why is that if i will just upload word document it will successfully inserted and it wil save to my database.

    Code:
    <?php 
     $conn = mysql_connect('localhost','root','');
      
      if(!$conn)
       {
         die(mysql_error());
       }
    
      mysql_select_db('uploadmovie',$conn);
      
      $createTB = "create table if not exists tbl_movie(
                            id int not null auto_increment,
    						video_file varchar(50),
    						type longtext,
    						size bigint,
    						content blob,
    						primary key(id))";
    						
       if(mysql_query($createTB))
        {
    	  echo "Table tbl_movie has been successfully created";
    	}
      
     
    
    
       $createTB2 = "create table if not exists tbl_mname(
                      mn_id int not null auto_increment,
    				  m_name varchar(30),
                      description varchar(50),
    				  m_author varchar(30),
    				  mf_id int,
    				  primary key(mn_id),
    				  foreign key (mf_id) references tbl_movie(id))";
    				  
    				  
    	if(mysql_query($createTB2))
        {
    	  echo "Table tbl_movie_name has been successfully created";
    	}
      
       die(mysql_error());  			  
    				  
                      				  
                                                 
       
     ?>

    And this is how i inserted...

    Code:
    <?php
       
         include_once("connectionDB.php");
    	 
         function uploadMovie($video_F,
    	                    $type,
    						$size,
    						$tmp_nme)
          {
    	  
             $sql = "INSERT INTO tbl_movie values(default,'$video_F','$type','$size','$tmp_nme')";
    		  
    		 $res=mysql_query($sql);
    		 
    		 if (!$res)
    		   return 'not succesfully inserted';
    		 else  
    		   return 'succesfully inserted';
    		   
    		 mysql_close();	    
          } 
    	  
    	  
    	  function add($name,$description,$author)
    	  {
    	    $sql = "insert into tbl_mname values(default,
    		                                     '$name',
    											 '$description',
    											 '$author',
    											  LAST_INSERT_ID()
    												  )";
    												  
    		  $result = mysql_query($sql);									  
    	     if (!$result)
    		   return ("FAILED TO INSERT".mysql_error());
    		 else  
    		   return 'succesfully inserted tbl_mname';
    		   
    	     mysql_close();	 
    	  }
    	  
    ?>
    Please help me thank you in advance.

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    I don't understand. If it works, what is the problem?

  5. #5
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,107
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    I don't understand. If it works, what is the problem?
    if it is a video,then it fails.

  6. #6
    SitePoint Wizard frank1's Avatar
    Join Date
    Oct 2005
    Posts
    1,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    first thing you can do is check what LAST_INSERT_ID() is returing inside the function(if both queries are are running successfully)

  7. #7
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,107
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I got the solution,it is in the php.ini the max_uploaded_size...i change it to bigger size,and now it's working i can upload the movie file.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •