Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 136,056 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,587 people online right now. Registration is fast and FREE... Join Now!




Images Into Database

 
Reply to this topicStart new topic

Images Into Database, (based on other thread)

capty99
5 Nov, 2002 - 05:38 PM
Post #1

the real kya
Group Icon

Joined: 26 Apr, 2001
Posts: 9,161



Thanked: 16 times
Dream Kudos: 550
My Contributions
i did the tute on that site that whoever supplied a link too and i cant get the code to work right.

CODE

<?
if (!isset($img1)) {
header("Location:
http://www.capty99.com/
insert_file.html");
exit;
}
// database configuration
$host = "localhost";
$user = "capty99";
$pass = "$$$$$$";
$db = "capty99";

$binary_junk = addslashes (fread(fopen($img1, "r"), filesize($img1)));

$insert_data = "INSERT INTO
images (img_id, binary_junk, filename, filesize, filetype)
VALUES ('1', '$binary_junk', '$img1_name', '$img1_size', '$img1_type')";
@mysql_query($insert_data) or
die("Couldn't insert data.");


?>


CODE

<HTML>
<HEAD>
<TITLE>Binary Data Insert Form</TITLE>
</HEAD>

<BODY>
<H1>Upload a File:</H1>

<FORM enctype="multipart/form-data"
method="post" action="do_insert.php">
<INPUT type="file" name="img1" size="30">
<INPUT type="submit" name="submit"
value="Use this File">

</FORM>
</BODY>
</HTML>


1st is the php file do_insert.php
2nd is the html file allowing them to upload images

anything wrong with this code?
User is offlineProfile CardPM
+Quote Post

capty99
RE: Images Into Database
5 Nov, 2002 - 05:41 PM
Post #2

the real kya
Group Icon

Joined: 26 Apr, 2001
Posts: 9,161



Thanked: 16 times
Dream Kudos: 550
My Contributions
oh yeah, the error i get is simple "cannont insert data"
User is offlineProfile CardPM
+Quote Post

klewlis
RE: Images Into Database
5 Nov, 2002 - 06:19 PM
Post #3

cur tu me vexas?
*****

Joined: 9 Nov, 2001
Posts: 1,723

you define your db login stuff, but you don't actually connect to the db. you need some lines like:
CODE

    mysql_connect("localhost", "capty99", "*****");
    @mysql_select_db("capty99") or die ("Unable to select database");


:)
User is offlineProfile CardPM
+Quote Post

capty99
RE: Images Into Database
5 Nov, 2002 - 06:29 PM
Post #4

the real kya
Group Icon

Joined: 26 Apr, 2001
Posts: 9,161



Thanked: 16 times
Dream Kudos: 550
My Contributions
oh, so i made one of those really smart mistakes...

son of a... haha.

gracias klewlis.
User is offlineProfile CardPM
+Quote Post

arniie
RE: Images Into Database
7 Nov, 2002 - 09:47 AM
Post #5

D.I.C Addict
****

Joined: 8 Oct, 2002
Posts: 999

also if your using php a lot. you'll want to (it would be better) to define these connection variables in an include. say.. DBConnectVars.inc.php (not just .inc - else can be viewed easily)

then you can just call the include at any point when using php

smile.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 05:58PM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month