Hey everybody,
I have a piece of script which is suppossed to store data from a form into a database.
It is all working except for the title - it is storing image blob, file type but not the imputted title.
The code is...
<?php
session_start();
if (!isset($_SESSION['db_is_logged_in']) || $_SESSION['db_is_logged_in'] !== true) {
header('Location: login.php');
exit;
}
require('includes/headercmsimage.php');
?>
<body>
<?php
if ($_POST['Submit']) {
if ($_POST['title']) {
if ($_POST['MAX_FILE_SIZE'] >= $_FILES['file']['size']) {
//print_r($_FILES);
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("resolve");
$photo = addslashes(fread(fopen($_FILES['file']['tmp_name'], "r"),
$_FILES['file']['size']));
$query = sprintf("INSERT INTO image(Title, Image, FileType) VALUES
('%s', '%s', '%s')",$title, $photo, $_FILES['file']['type']);
if (mysql_query($query)) {
$messages[] = "Your image has been successfully stored in the database";
} else {
$messages[]= mysql_error();
}
} else {
$messages[]="The file is bigger than the allowed size please resize";
}
}
}
?>
<body><br>
<?
if (isset($messages)) {
foreach ($messages as $message) {
print $message ."<br>";
}
}
?>
<table width="525" border="0" align="center" cellpadding="30" cellspacing="1" bgcolor="#999999">
<tr>
<td align="left" bgcolor="#FFFFFF">
<br><form action="" method="post" enctype="multipart/form-data" name="form1">
Title: <input name="title" type="text"><br><br>
Image: <input type="file" name="file">
<input type="hidden" name="MAX_FILE_SIZE" value="2000000"><br><br>
<input type="submit" name="Submit" value="Submit">
</form><br>
</td>
</tr>
</table>
</body>
</html>
<?php
require('includes/footer.php');
?>
Please help it is driving me crazy!