Looking for a form with image upload and having info get stored into database

Hey All,

Very new to php and I am trying to create a form with these features.

Model #

When the admin submits that info it gets stored into a database.

Is there any kind of tutorial that will show me exactly how to do this? I tried it myself but I cannot get it to work.

Form Code

<form method="post" action="post.php">
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<td colspan="3"><strong>Add Product</strong></td>
<td width="78">Equipment Name</td>
<td width="6">:</td>
<td width="294"><input name="name" type="text" id="name" style="width:250px;"></td>
<td>Model #</td>
<td><input name="model" type="text" id="model" style="width:250px;"></td>
<td><input name="desc" type="text" id="desc" style="width:250px; height:100px;"></td>
<td>Upload Image</td>
<td><input type="hidden" name="MAX_FILE_SIZE" value="25000"> <input type="file" name="imgfile">
<font size="1">Click browse to upload a local file</font></td>
<td><input type="submit" name="Submit" value="Submit"></td>

Post.php code

// Pick up the form data and assign it to variables
$name = $_POST['name'];
$model = $_POST['model'];
$desc = $_POST['desc'];
$image = $_POST['image'];

// contact to database

$connect = mysql_connect("localhost", "username", "password") or die ("Error , check your server connection.");



//Get data in local variable



// check for null values

if ($v_name==""  or $v_model=="")

echo "All fields must be entered, hit back button and re-enter information";


$query="insert into test(name, model, desc, image) values('$v_name','$v_model','$v_desc','$v_image'')";

mysql_query($query)  or die(mysql_error());


// Redirect
header("Location: ../admin/Admin_AddListing.php");


Any help would be greatly appreciated.

First off, break this job down into 2 distinct parts.

a) create the basic form without the image, and save the data to your database.

b) the upload and storage of the image

Nail a) first.

Get the data added to your database without the image for now.

Then go to this Manual page Handling file uploads and read it thoroughly. File uploading is absolutely full of traps and gotchas – you really need to understand everything about them, how and where to set file size limits, how to check for errors and so on. There is no shortcut, no copy/paste code that will get you over this hurdle. Put the work in and it will pay dividends.

When you have done that, tack b) onto your form.

ps read up on mysql_real_escape_string() because the code you have showed is very vulnerable to sql injection attacks.

pps after the redirect add: