relative php noob needs help, have tried 3 or 4 differnet ways to get an image along with other post data from an html form to save into a mysql db. other data saves fine, no luck at all with image. php and form code below. HELP. Thanks in advance.
<?php
include 'config.php';
include 'opendb.php';
$pass = $_POST['blogpass'];
$title = $_POST['title'];
$post = $_POST['post'];
$category = $_POST['category'];
$blogimage = $_POST['blogimage'];
if(isset($_POST['add']))
{
if ($pass == "[I]password[/I]")
{
$query = "INSERT INTO [I]tablename[/I] (title, post, category) VALUES ('$title', '$post', '$category')";
mysql_query($query) or die('Error, insert query failed');
$handle = fopen($blogimage,'r');
$file_content = fread($handle,filesize($blogimage));
fclose($handle);
$encoded = chunk_split(base64_encode($file_content));
$sql = "UPDATE braindump SET blogimage='$encoded' where title='$title' and category='$category'";
mysql_query($sql);
}
$query = "FLUSH PRIVILEGES";
mysql_query($query);
include 'closedb.php';
echo "Your Post has been submitted";
}
else
{
?>
<form method="post" enctype="multipart/form-data" OnSubmit="setTimeout('clear_form()', 2000); return true" action="<?php $_SERVER["PHP_SELF"];?>">
<table width="100%" border="0" cellpadding="0">
<tr>
<td colspan="2" width="100%" valign="top">
<p align="center" class="style4">Blog Form
</p>
</td>
</tr>
<tr>
<td width="20%" valign="top">
<p align="center" class="style4">Post Title
</p>
</td>
<td width="80%">
<p align="left">
<select name="category" size="7">
<option value="Current Events">Current Events</option>
<option value="Economy">Economy</option>
<option value="Green">Green</option>
<option value="Kitchen Sink">Kitchen Sink</option>
<option value="Politics">Politics</option>
<option value="Pop Culture">Pop Culture</option>
<option value="SciTech">SciTech</option>
</select><br /><br />
<input name="title" type="text" size="100" maxlength="130" /><br /><br />
</p>
</td>
</tr>
<tr>
<td width="20%">
<p align="center" class="style4">Blog Post
</p>
</td>
<td width="80%">
<p align="left"><textarea name="post" cols="75" rows="15"></textarea>
</p>
</td>
</tr>
<tr>
<td width="20%" valign="top">
<p align="center" class="style4">Blog Post Password
</p>
</td>
<td width="80%">
<p align="left"><input name="blogpass" type="text" size="100" maxlength="130" /><br /><br />
</p>
</td>
</tr>
<tr>
<td width="20%" valign="top">
<p align="center" class="style4">Image Attach
</p>
</td>
<td width="80%">
<p align="left"><input name="blogimage" type="file" /><br /><br />
</p>
</td>
</tr>
<tr>
<td width="20%" valign="top">
</td>
<td width="80%">
<p align="left"><input name="add" type="submit" id="add" value="Submit" /><br /><br />
</p>
</td>
</tr>
</table>
</form>