I am trying to create a simple photoalbum using mysql and php.
I wanted to display the images with its descripion on my webpage.
First i created a table using the following code.
Code: Select all
CREATE TABLE photo(
id INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY,
description CHAR(255),
bin_data LONGBLOB,
filename CHAR(50),
filesize CHAR(50),
filetype CHAR(50)
);Code: Select all
<?php
// code that will be executed if the form has been submitted:
if ($submit) {
// connect to the database
// (you may have to adjust the hostname,username or password)
MYSQL_CONNECT("localhost","root","password");
mysql_select_db("dbname");
$data = addslashes(fread(fopen($form_data, "r"), filesize($form_data)));
$result=MYSQL_QUERY("INSERT INTO photo(description,bin_data,filename,filesize,filetype) ".
"VALUES ('$form_description','$data','$form_data_name','$f
orm_data_size','$form_data_type')");
$id= mysql_insert_id();
print "<p>This file has the following Database ID: <b>$id</b>";
MYSQL_CLOSE();
} else {
// else show the form to submit new data:
?>
<form method="post" action="<?php echo $PHP_SELF; ?>" enctype="multipart/form-data">
File Description:<br>
<input type="text" name="form_description" size="40">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000">
<br>File to upload/store in database:<br>
<input type="file" name="form_data" size="40">
<p><input type="submit" name="submit" value="submit">
</form>
<?php
}
?>I am new to php and checked a few tutorial to get it completed.
Please help to get it worked.
Thanks in advance,
Jan
feyd | please use formatting!