I want to add all the form values to my database, i know how to insert new records, but with the “Image” i would like to upload, i`m stuck.
What would be the simplest way to insert all from values and upload the image and insert the image url in the database?
Form Source:
<form action="_eventcreate.php" id="contactform" method="POST">
<p>
<label for="event_name">Event Name:</label>
<input type="text" name="event_name" class="input" value="">
</p><p>
<label for="event_description">Description:</label>
<input type="text" name="event_description" cols="88" rows="6" class="input" value="">
</p><p>
<label for="event_date">Event Date:</label>
<input type="text" name="event_date" class="input" value="">
</p><p>
<label for="event_time">Event Time:</label>
<input type="text" name="event_time" class="input" value="">
</p><p>
<label for="event_cost">Event Cost:</label>
<input type="text" name="event_cost" class="input" value="">
</p><p>
<label for="event_image">Upload Image:</label>
<input type="file" name="fileField" id="fileField" />
</p>
<input type="submit" name="submit" value="Create Event" class="submit">
</form>
Thanks!
1) Use
<input type="file" name="image"/>for the upload.2) In the form tag add:
enctype="multipart/form-data"3) Use the
$_FILEScollection to get the info about the uploaded file(s).4) Use
is_uploaded_file(),move_uploaded_file()to check for the file & move it to its final destination.5) Make sure you save the file in a directory which is accessible through the web & create a URL for it to be saved in the database.
Check out: http://www.php.net/manual/en/features.file-upload.post-method.php