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">&nbsp;
		</td>
		<td width="80%">
			<p align="left"><input name="add" type="submit" id="add" value="Submit" /><br /><br />
			</p>
		</td>
	</tr>
</table>
</form>

dwatycha,

For file upload, you really need to do some background reading. The PHP Manual is a good place to start:
http://www.php.net/manual/en/features.file-upload.php

But if you want to avoid a lot of heartache, then there's no shame in using a ready-written downloadable php blog script. There are many to choose from and most will represent at least a few hundred man-hours of effort, maybe a man-year or more! Notwithstanding your undoubted talent, you will find it hard to compete with that, and will be able to devote your time to customising the appearance of your blog rather than worrying about all that nauseating code. stuff ;)

You will find many free and pay-for blog scripts in the web, eg. here, and many other good download sites.

Airshow

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.