Database Insert
Posted by:
Lee Maskell ()
Date: November 13, 2008 02:30PM
Am new to Mysql so please go easy. Have created a form to add a profile to a database (id, name, description, image) which works fine if all fields are populated by the user, but if one isnt then it wont add the new profile. Im not sure if this is an issue with the Mysql code or the way ive set up the db, would appreciate a few pointers.
Mysql Code:
<?php
$con=mysql_connect(localhost,user,password);
mysql_select_db(database);
if(isset($_REQUEST['submit']))
{
$imgtype=$_FILES['uploadfile']['type'];
$name=$_REQUEST['name'];
$description=$_REQUEST['description'];
if($imgtype=="image/jpeg" || $imgtype=="image/jpg" || $imgtype=="image/pjpeg" || $imgtype=="image/gif" || $imgtype=="image/x-png" || $imgtype=="image/bmp")
{
$image=$_FILES['uploadfile']['tmp_name'];
$fp = fopen($image, 'r');
$content = fread($fp, filesize($image));
$content = addslashes($content);
fclose($fp);
$sql="insert into nnpg_profile (profile_name,profile_content,profile_image) values ('$name','$description', '$content')";
$res=mysql_query($sql) or die (mysql_error());
}
}
?>
Table structure
CREATE TABLE IF NOT EXISTS `table` (
`profile_id` tinyint(4) NOT NULL auto_increment,
`profile_name` varchar(100) NOT NULL,
`profile_content` mediumtext NOT NULL,
`profile_image` mediumblob,
PRIMARY KEY (`profile_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=11 ;
Thanks