Skip navigation links

MySQL Forums


Advanced Search

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

Options: ReplyQuote


Subject Written By Posted
Database Insert Lee Maskell 11/13/2008 02:30PM
Re: Database Insert Peter Brawley 11/13/2008 04:15PM
Re: Database Insert Lee Maskell 11/13/2008 05:16PM
Re: Database Insert Peter Brawley 11/13/2008 05:45PM
Re: Database Insert Lee Maskell 11/14/2008 02:26AM
Re: Database Insert Peter Brawley 11/14/2008 08:42AM
Re: Database Insert Lee Maskell 11/14/2008 08:57AM
Re: Database Insert Peter Brawley 11/14/2008 09:22AM
Re: Database Insert Lee Maskell 11/15/2008 03:39AM
Re: Database Insert Peter Brawley 11/15/2008 10:54AM
Re: Database Insert Lee Maskell 11/15/2008 12:43PM
Re: Database Insert Peter Brawley 11/15/2008 02:26PM
Re: Database Insert Lee Maskell 11/16/2008 06:51AM
Re: Database Insert Peter Brawley 11/16/2008 10:19AM
Re: Database Insert Lee Maskell 11/18/2008 06:07AM
Re: Database Insert Peter Brawley 11/18/2008 09:40AM
Re: Database Insert Lee Maskell 11/18/2008 10:09AM


Sorry, you can't reply to this topic. It has been closed.