upload images into MySQL

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
webss
Forum Newbie
Posts: 2
Joined: Thu May 25, 2006 8:04 pm

upload images into MySQL

Post by webss »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I want to store images into mysql databse as blob type. Tables already been set up.
The syntax using to upload:

Code: Select all

<HTML>
<HEAD></HEAD>
<BODY>
<?php
	if ($submit) {

	$db = MYSQL_CONNECT("localhost", "root", "1128");
	mysql_select_db("project", $db) or die(mysql_errno() . ": " . mysql_error() . "<br>");
	echo "Database has been connected.";

    	$data = addslashes(fread(fopen($binFile, "r"), filesize($binFile)));
    	$strDescription = addslashes(nl2br($txtDescription));
    	$sql = "INSERT INTO routine
    	          (Dest, Images, Descrip)
    	          VALUES ('$binFile_name', '$binFile', '$strDescription')";
    	$result = mysql_query($sql, $db); 
    	echo "Thank you. The new file was successfully added to your database.<br><br>";

  	MYSQL_CLOSE();
	} else {
?>
	<HTML>
	<BODY>
	<FORM METHOD="post" ACTION="<?php echo $PHP_SELF; ?>" ENCTYPE="multipart/form-data">
 	<INPUT TYPE="hidden" NAME="MAX_FILE_SIZE" VALUE="1000000">
 	<INPUT TYPE="hidden" NAME="action" VALUE="upload">
 	<TABLE BORDER="1">
  	<TR>
   	<TD>Description: </TD>
   	<TD><TEXTAREA NAME="txtDescription" ROWS="10" COLS="50"></TEXTAREA></TD>
  	</TR>
  	<TR>
  	<TD>File: </TD>
   	<TD><INPUT TYPE="file" NAME="binFile"></TD>
  	</TR>
  	<TR>
   	<TD COLSPAN="2"><INPUT TYPE="submit" VALUE="submit"></TD>
  	</TR>
 	</TABLE>
	</FORM>
<?php
	}
?>
</BODY>
</HTML>
the result of execution like this:
PHP Notice: Undefined variable: submit in c:\Inetpub\wwwroot\upload.php on line 5 PHP Notice: Undefined variable: PHP_SELF in c:\Inetpub\wwwroot\upload.php on line 25

Can anyone tell me what's wrong? Thx :(


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

  1. images in database, bad idea far more often than not.
  2. you're getting errors because register_globals is off (which it should be.)
  3. Looking for the submit button isn't the best of ideas. Look for a field that should always be in the submission instead or better yet, look at $_SERVER['REQUEST_METHOD']
$_POST['submit'] if anything..
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

is there any specific reason why you can't just store the image url?
webss
Forum Newbie
Posts: 2
Joined: Thu May 25, 2006 8:04 pm

Post by webss »

Sorry. I have not had a chance to check the reply after I submited the question. This has been done. Thx for answering anyway. Cheers
Post Reply