
Originally Posted by
guido2004
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.
Bookmarks