| | |
html form to php mysql db insert for image
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Oct 2007
Posts: 1
Reputation:
Solved Threads: 0
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 == "password")
{
$query = "INSERT INTO tablename (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> Last edited by Ezzaral; Apr 24th, 2009 at 1:32 pm. Reason: Added [code] [/code] tags. Please use them to format any code that you post.
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
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
Last edited by Airshow; Apr 24th, 2009 at 5:39 pm. Reason: Typos
![]() |
Similar Threads
- how to retrive image file from mysql databse using php (PHP)
- Need help with a few problems in PHP and MySQL (PHP)
- How to insert image in MySQL....... (PHP)
- php mysql image again PLEASE HELP (PHP)
- php script (PHP)
- Php Mysql Image Question (PHP)
- Mysql num rows(): Invalid argument (PHP)
- Problems with first php file (PHP)
Other Threads in the PHP Forum
- Previous Thread: Execute Once?
- Next Thread: Directories Problem
| Thread Tools | Search this Thread |
advanced alerts apache api archive array autosuggest beginner binary broken cakephp checkbox class clients cms code cron curl database date datepart display dynamic echo email emptydisplayvalue eregi error execute explodefunction file files folder form forms function functions google hack head href htaccess html if...loop image include insert ip javasciptvalidation javascript joomla keywords library limit link login mail matching menu mlm multiple mysql number object oop password paypal pdf php phpincludeissue query radio random recursive remote script search searchbox server sessions shot smarty source space speed sql syntax system table tutorial update upload url validator variable vbulletin video web website youtube





