MySQL Forums
Forum List  »  PHP

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
November 13, 2008 02:30PM
November 13, 2008 04:15PM
November 13, 2008 05:16PM
November 13, 2008 05:45PM
November 14, 2008 02:26AM
November 14, 2008 08:42AM
November 14, 2008 08:57AM
November 14, 2008 09:22AM
November 15, 2008 03:39AM
November 15, 2008 10:54AM
November 15, 2008 12:43PM
November 15, 2008 02:26PM
November 16, 2008 06:51AM
November 16, 2008 10:19AM
November 18, 2008 06:07AM
November 18, 2008 09:40AM
November 18, 2008 10:09AM


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

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.