Jump to content

Never did this before, so seeking FORM / Uploading Images help ...


spacepoet

Recommended Posts

Hello:

 

I would like to know how I can add the option to upload JPGs and/or PDFs to the form I have.

 

I believe I will need to allow 3 uploads once the whole form is done, but I'm trying to keep it small as I learn this.

 

Currently, the form saves the data to the database, and emails the results to a contact. This is fine - just what I need to do most of the time.

 

However, what I'm interesting in doing for this form is to allow the end user to upload/attached JPGs and/or PDFs and save then to the database (and I believe I will need to save the files in a folder on the server, I have one called "EmailedImages"),

and then email the results to the contact, including links that will allow the contact to click and download the attached JPGs and/or PDFs.

 

I haven't done this before, so can someone point me in the direction of how to do this, or should an example with the code I use:

<?php

$error = NULL;
$myDate = NULL;
$FullName = NULL;
$Email = NULL;

if(isset($_POST['submit'])) {

$myDate = $_POST['myDate'];
$FullName = $_POST['FullName'];
$Email = $_POST['Email'];


if(empty($FullName)) {
   $error .= '-- Enter your Full Name. <br />';
}

if(empty($Email)) {
   $error .= '-- Enter your Email. <br />';
}

if($error == NULL) {

$sql = sprintf("INSERT INTO myContactData(myDate,FullName,Email) VALUES ('%s','%s','%s')",

                        mysql_real_escape_string($myDate),
                        mysql_real_escape_string($FullName),
                        mysql_real_escape_string($Email);

                        
  if(mysql_query($sql)) {
  
    $error .= 'Thank you for contacting us.';
    
mail( "[email protected]", "Contact Request",

"Date Sent: $myDate\n Full Name: $FullName\n Email: $Email\n",
"From: $Email" );
  }
  else {
    $error .= 'There was an error in our Database, please Try again!';
  }
}
}
echo '<span class="textError">' . $error . '</span>';

?>



<form name="myform" action="" method="post">
<input type="hidden" name="myDate" size="45" maxlength="50" value="<?php echo date("F j, Y"); ?>" />


Full Name: <input type="text" name="FullName" size="45" maxlength="50" value="<?php echo $FullName; ?>" />
Email: <input type="text" name="Email" size="45" maxlength="50" value="<?php echo $Email; ?>" />


<input type="submit" name="submit" value="Submit" />

</form>

 

Any help would be greatly appreciated!

yep just add a field to your database. then add a <input type="file" name="database_field_name"/>

 

and then you need to just add the new filename and location (once its uploaded and moved - follow the tutorial) to your database table.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.