I'm doing a form in PHP. I started using jQuery to make a select dropdown more interactive. Depending on your option, you will receive a new select dropdown with other options. The problem comes when you take the first option, the value is always the same.
$('#options').on('change', function(e) {
$('.option').hide();
$('#option-' + e.target.value).show();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="form-group col-md-6">
<label>Contract type</label>
<select id="options" class="form-control" name="typeContract" required>
<option value="" selected disabled>Select options </option>
<option value="light">Light</option>
<option value="gas">Gas</option>
</select>
<div id="option-light" class="option" style="display: none;">
<br>
<select class="form-control" name="nameContract" required>
<option value="light1">1</option>
<option value="light2">2</option>
<option value="light3">3</option>
</select>
</div>
<div id="option-gas" class="option" style="display: none;">
<br>
<select class="form-control" name="nameContract" required>
<option value="gas1">gas1</option>
<option value="gas2">gas2</option>
</select>
</div>
</div>
You were very close.
But the jquery code tried to show an element with the id option-light or option-gas which do not exist in your code. So if you change your id's it works.
As pointed out by Carsten in the comments id should always be unique
<div class="form-group col-md-6">
<label>Contract type</label>
<select id="options" class="form-control" name="typeContract" required>
<option value="" selected disabled>Select options </option>
<option value="light">Light</option>
<option value="gas">Gas</option>
</select>
<div id="option-light" class="option" style="display: none;">
<br>
<select class="form-control" name="nameContract" required>
<option value="light1">1</option>
<option value="light2">2</option>
<option value="light3">3</option>
</select>
</div>
<div id="option-gas" class="option" style="display: none;">
<br>
<select class="form-control" name="nameContract" required>
<option value="gas1">gas1</option>
<option value="gas2">gas2</option>
</select>
</div>
</div>
This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 3 years ago.
My form throws an error in PHP when submitting form data via email. Not sure what I did wrong/am missing.
Form:
<div class="row">
<div class="col">
<form id="msform" action="submit.php" method="post" data-autosubmit>
<!-- Step 1 -->
<fieldset>
<h2 class="fs-title">Step 1</h2>
<h3 class="fs-subtitle">Tell us about your device.</h3>
<div class="form-group">
<label for="brand">Brand</label>
<select class="form-control" id="brand" name="brand" required>
<option value="" selected data-default>- Device Brand -</option>
<option value="Apple">Apple</option>
<option value="Samsung">Samsung</option>
</select>
</div>
<div class="form-group">
<label for="model">Model</label>
<select class="form-control" id="model" name="model" required>
<option value="" selected data-default>- Device Model -</option>
<option value="iPhone 8">iPhone 8</option>
<option value="iPhone X">iPhone X</option>
<option value="Galaxy S8">Galaxy S8</option>
<option valaue="Galaxy S9">Galaxy S9</option>
<option value="Galaxy S10">Galaxy S10</option>
</select>
</div>
<div class="form-group">
<label for="variant">Storage</label>
<select class="form-control" id="variant" name="variant" required>
<option value="" selected data-default>- Storage Size -</option>
<option value="iPhone 8 - 64GB">iPhone 8 - 64GB</option>
<option value="iPhone 8 - 256GB">iPhone 8 - 256GB</option>
<option value="iPhone X - 64GB">iPhone X - 64GB</option>
<option value="iPhone X - 256GB">iPhone X - 256GB</option>
<option value="Galaxy S8 - 64GB">Galaxy S8 - 64GB</option>
<option valaue="Galaxy S9 - 64GB">Galaxy S9 - 64GB</option>
<option value="Galaxy S10 - 128GB">Galaxy S10 - 128GB</option>
</select>
</div>
<input type="button" name="next" class="next action-button" value="Next" />
</fieldset>
<!--Step 1 End-->
<!--Step 2-->
<fieldset>
<h2 class="fs-title">Step 2</h2>
<h3 class="fs-subtitle">Now we need to know more about your device's condition.</h3>
<div class="form-group">
<label for="screen">How is your device's <b>screen</b>?</label>
<select class="image-picker form-control" id="screen" name="screen" required>
<option value="0" data-img-src="">Flawless, no scratches!</option>
<option value="1" data-img-src="">1-2 light scratches</option>
<option value="2" data-img-src="">3 or more scratches</option>
<option value="3" data-img-src="">Cracked or damaged</option>
</select>
</div>
<div class="form-group">
<label for="body">How is your device's <b>housing</b>?</label>
<select class="form-control" id="body" name="body" required>
<option value="0">Flawless, no scratches or bends!</option>
<option value="1">1-2 light scratches</option>
<option value="2">3 or more scratches</option>
<option value="3">Bent or severely damaged</option>
</select>
</div>
<div class="form-group">
<label for="power">Is your device able to <b>power on</b>?</label>
<select class="form-control" id="power" name="power" required>
<option value="0">Yes</option>
<option value="1">No</option>
</select>
</div>
<input type="button" name="previous" class="previous action-button-previous" value="Previous" />
<input type="button" name="next" class="next action-button" value="Next" />
</fieldset>
<!--Step 2 End-->
<!--Step 3-->
<fieldset>
<h2 class="fs-title">Step 3</h2>
<h3 class="fs-subtitle">Just a little more information needed, almost there!</h3>
<div class="form-group">
<label for="battery">Does your device have a faulty battery?</label>
<select class="form-control" id="battery" name="battery" required>
<option value="0">Yes</option>
<option value="1">No</option>
</select>
</div>
<div class="form-group">
<label for="charge">Is your device able to <b>charge</b>?</label>
<select class="form-control" id="charge" name="charge" required>
<option value="0">Yes</option>
<option value="1">No</option>
</select>
</div>
<div class="form-group">
<label for="calls">Is your device able to <b>make and receive calls</b>?</label>
<select class="form-control" id="calls" name="calls">
<option value="0">Yes</option>
<option value="1">No</option>
</select>
</div>
<div class="form-group">
<label for="fcamera">Does your <b>front camera work</b>?</label>
<select class="form-control" id="fcamera" name="fcamera">
<option value="0">Yes</option>
<option value="1">No</option>
</select>
</div>
<div class="form-group">
<label for="rcamera">Does your <b>rear camera work</b>?</label>
<select class="form-control" id="rcamera" name="rcamera">
<option value="0">Yes</option>
<option value="1">No</option>
</select>
</div>
<div class="form-group">
<label for="water">Is your device <b>water damaged</b>?</label>
<select class="form-control" id="water" name="water">
<option value="0">Yes</option>
<option value="1">No</option>
</select>
</div>
<div class="form-group">
<label for="wifi">Is your device able to connect using WiFi?</label>
<select class="form-control" id="wifi" name="wifi">
<option value="0">Yes</option>
<option value="1">No</option>
</select>
</div>
<input type="button" name="previous" class="previous action-button-previous" value="Previous" />
<input type="button" name="next" class="next action-button" value="Next" onclick="getFinalPrice();" />
</fieldset>
<!--End Step 3-->
<!--Final-->
<fieldset>
<h2 class="fs-title">Value</h2>
<h3 class="fs-subtitle">Here's how much we can offer for your device.</h3>
<h2 id="finalValue"></h2>
<hr>
<h3 class="fs-subtitle">If you're happy with our offer, please fill in your contact details below and we'll arrange for free a pickup of your device.</h3>
<div class="form-group">
<label for="firstname">Name</label>
<input type="text" class="form-control" placeholder="Full Name" name="name" required>
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" class="form-control" placeholder="example#example.com" name="email" required>
</div>
<div class="form-group">
<label for="number">Phone Number</label>
<input type="number" class="form-control" placeholder="91234567" name="number" required>
<small id="numberHelp" class="form-text text-muted">We'll never share your email and phone number with anyone else.</small>
</div>
<input type="button" name="previous" class="previous action-button-previous" value="Previous" />
<input type="submit" name="submit" class="submit action-button" value="Submit" />
</fieldset>
<!--Final End-->
</form>
</div>
</div>
<!-- /.MultiStep Form -->
</body>
</html>
PHP Script:
<?php
$name = $_POST['name'];
$number = $_POST['number'];
$email = $_POST['email'];
$brand = $_POST['brand'];
$model = $_POST['model'];
$variant = $_POST['variant'];
$screen = $_POST['screen'];
$body = $_POST['body'];
$power = $_POST['power'];
$battery = $_POST['battery'];
$charge = $_POST['charge'];
$calls = $_POST['calls'];
$fcamera = $_POST['fcamera'];
$rcamera = $_POST['rcamera'];
$water = $_POST['water'];
$wifi = $_POST['wifi'];
$formcontent = "From: $name \n Contact: $number \n Device Brand: $brand \n Device Model: $model \n Device Variant: $variant \n How is your device's screen? $screen \n How is your device's housing? $body \n Is your device able to power on? $power \n Does your device have a fault battery? $battery \n Is your device able to charge? $charge \n Does your front camera work? $fcamera \n Does your rear camera work? $rcamera \n Is your device water damaged? $water \n Is your device able to connect using WiFi? $wifi";
$recipient = "example#example.com";
$subject = "Buyback Request";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank you! We'll be in contact soon. You'll now be redirected back to our main webpage.";
/* Redirect browser */
header("Location: https://example.com");
/* Make sure that code below does not get executed when we redirect. */
exit;
?>
I gave the input options all a name value so that PHP knows where to find the data. Not sure if this is the correct way of doing it.
Currently, the form always throws an error on submission.
All help is appreciated, thank you!
I am new to posting on this site and PHP...I am trying to jump in on this site and make some updates. I don't see any redirect after the form is submitted. I was going to add an action, but don't want to cause and error. Can someone please lead me in the right direction. Any help is appreciated. Here is the code:
<!DOCTYPE html>
<html lang="en">
<head>
<?php $this->load->view('includes/meta'); ?>
<script>
function varifyForm(){
if(document.getElementById('terms').checked == false){
alert('Please Accept Terms and Conditions');
return false;
}else if(document.getElementById('privacy').checked == false){
alert('Please Accept Privacy Policy');
return false;
}else{
return true;
}
}
</script>
</head>
<body>
<!--------------------------------HEADER------------------------------------------->
<?php $this->load->view('includes/header'); ?>
<!--------------------------------HEADER------------------------------------------->
<!--------------------------------BODY------------------------------------------->
<div class="body">
<div class="container">
<div class="full" style="margin:15px 0;">
<h2 align="center">Registration – Member</h2>
<div class="col-md-12">
<form method="post" class="col-md-6 col-md-offset-3" onSubmit="return varifyForm()">
<?php
if( $this->session->flashdata('error_msg') != ''){
?>
<p style="font-weight:bold; color:#F00;"><?php echo $this->session->flashdata('error_msg'); ?></p>
<?php
}
?>
<?php
if( $this->session->flashdata('success_msg') != ''){
?>
<p style="font-weight:bold; color:#0F0;"><?php echo $this->session->flashdata('success_msg'); ?></p>
<?php
}
?>
<div class="row">
<div class="col-sm-4">
<div class="form-group">
<label for="">First Name:</label>
<input type="text" class="form-control" id="" name="terms[first_name]" value="<?php if($this->session->flashdata('first_name') != ''){ _e($this->session->flashdata('first_name')); } ?>" required>
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<label for="">Last Name:</label>
<input type="text" class="form-control" id="" name="terms[last_name]" value="<?php if($this->session->flashdata('last_name') != ''){ _e($this->session->flashdata('last_name')); } ?>" required>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label for="">Cell Phone No:</label>
<input type="tel" class="form-control" id="" name="terms[phone_no]" value="<?php if($this->session->flashdata('phone_no') != ''){ _e($this->session->flashdata('phone_no')); } ?>" required>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-4">
<div class="form-group">
<label for="">Email:</label>
<input type="email" class="form-control" id="" name="terms[email]" value="<?php if($this->session->flashdata('email') != ''){ _e($this->session->flashdata('email')); } ?>" required>
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<label for="">Password:</label>
<input type="password" class="form-control" id="" name="password" value="" required>
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<label for="">Confirm Password:</label>
<input type="password" class="form-control" id="" name="confirm_password" value="" required>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-4">
<div class="form-group">
<label for="">Address:</label>
<textarea class="form-control" name="terms[address]"><?php if($this->session->flashdata('address') != ''){ _e($this->session->flashdata('address')); } ?></textarea>
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<label for="">City:</label>
<input type="text" class="form-control" id="" name="terms[city]" value="<?php if($this->session->flashdata('city') != ''){ _e($this->session->flashdata('city')); } ?>" required>
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<label for="">State:</label>
<select name="terms[state]" class="form-control" >
<option value="" selected="selected">State / Province</option>
<option value="Alabama">Alabama</option>
<option value="Alaska">Alaska</option>
<option value="Arizona">Arizona</option>
<option value="Arkansas">Arkansas</option>
<option value="California">California</option>
<option value="Colorado">Colorado</option>
<option value="Connecticut">Connecticut</option>
<option value="Delaware">Delaware</option>
<option value="District of Columbia">District of Columbia</option>
<option value="Florida">Florida</option>
<option value="Georgia">Georgia</option>
<option value="Hawaii">Hawaii</option>
<option value="Idaho">Idaho</option>
<option value="Illinois">Illinois</option>
<option value="Indiana">Indiana</option>
<option value="Iowa">Iowa</option>
<option value="Kansas">Kansas</option>
<option value="Kentucky">Kentucky</option>
<option value="Louisiana">Louisiana</option>
<option value="Maine">Maine</option>
<option value="Maryland">Maryland</option>
<option value="Massachusetts">Massachusetts</option>
<option value="Michigan">Michigan</option>
<option value="Minnesota">Minnesota</option>
<option value="Mississippi">Mississippi</option>
<option value="Missouri">Missouri</option>
<option value="Montana">Montana</option>
<option value="Nebraska">Nebraska</option>
<option value="Nevada">Nevada</option>
<option value="New Hampshire">New Hampshire</option>
<option value="New Jersey">New Jersey</option>
<option value="New Mexico">New Mexico</option>
<option value="New York">New York</option>
<option value="North Carolina">North Carolina</option>
<option value="North Dakota">North Dakota</option>
<option value="Ohio">Ohio</option>
<option value="Oklahoma">Oklahoma</option>
<option value="Oregon">Oregon</option>
<option value="Pennsylvania">Pennsylvania</option>
<option value="Rhode Island">Rhode Island</option>
<option value="South Carolina">South Carolina</option>
<option value="South Dakota">South Dakota</option>
<option value="Tennessee">Tennessee</option>
<option value="Texas">Texas</option>
<option value="Utah">Utah</option>
<option value="Vermont">Vermont</option>
<option value="Virginia">Virginia</option>
<option value="Washington">Washington</option>
<option value="West Virginia">West Virginia</option>
<option value="Wisconsin">Wisconsin</option>
<option value="Wyoming">Wyoming</option>
<option value="Armed Forces Americas">Armed Forces Americas</option>
<option value="Armed Forces Europe">Armed Forces Europe</option>
<option value="Armed Forces Pacific">Armed Forces Pacific</option>
</select>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-4">
<div class="form-group">
<label for="">Zip Code:</label>
<input type="text" class="form-control" id="" name="terms[zip]" value="<?php if($this->session->flashdata('zip') != ''){ _e($this->session->flashdata('zip')); } ?>" required>
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<label for="">Your Cause:</label>
<select name="terms[cause]" class="form-control" required>
<option value="">Select A User</option>
<?php
foreach($causes as $value){
$cause_name = $value['nonprofit_name'];
?>
<option value="<?php _e($value['user_id']); ?>" <?php if($this->session->flashdata('cause') != '' AND $this->session->flashdata('cause') == $value['user_id']){ ?> selected <?php } ?>><?php _e($cause_name); ?></option>
<?php
}
?>
</select>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label for="">How did you hear about this website ?:</label>
<textarea class="form-control" name="terms[about]"><?php if($this->session->flashdata('about') != ''){ _e($this->session->flashdata('about')); } ?></textarea>
</div>
</div>
</div>
<div class="form-group">
<label for="">Terms and Conditions:</label><br>
<input type="checkbox" id="terms"> I agree to the Terms and Conditions
</div>
<div class="form-group">
<label for="">Privacy Policy:</label><br>
<input type="checkbox" id="privacy"> I agree to the Privacy Policy
</div>
<button type="submit" name="btnSignUp" value="signup" class="btn btn-primary"><p style="margin:0;">NEXT</p></button>
</form>
</div>
</div>
</div>
</div>
<!--------------------------------BODY------------------------------------------->
<!--------------------------------FOOTER------------------------------------------->
<?php $this->load->view('includes/footer'); ?>
<!--------------------------------FOOTER------------------------------------------->
<!-- container / end -->
<!--------------------------------JQUERY------------------------------------------->
<script src="<?php echo base_url(); ?>assets/js/jquery.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="<?php echo base_url(); ?>assets/js/bootstrap.min.js"></script>
<script src="<?php echo base_url(); ?>assets/js/wow.min.js"></script>
<script>
new WOW().init();
</script>
</body>
</html>
I'm finding it nearly impossible to get this upload into mySQL database. The "create_news" file is currently uploading both of my files (file and image) onto my server, but then I receive this error when it tries to insert the information into my mySQL db:
Error: visible, homepage, type, publication_name, publication_url, month, date, year, title, author, summary, full_text, tag_1, tag_2, tag_3, tag_4, tag_5, tag_6, tag_7, image, image_type, image_size, file, file_type, file_size ) VALUES ( 'N', 'N', 'N', '', '', '', '', '', 't', '', '', '', '', '', '', '', '', '', '', '18068-','','0', '8776-','','0')
The upload was inserting into mySQL before I added file uploads. Here is my form page:
<?php require_once($_SERVER['DOCUMENT_ROOT']."/includes/session.php");?>
<?php require_once($_SERVER['DOCUMENT_ROOT']."/includes/db_connection.php");?>
<?php session_start();
if($_SESSION["login_user"] != true) {
echo("Access denied!");
exit();
}
?>
<?php require_once($_SERVER['DOCUMENT_ROOT']."/includes/functions.php");?>
<?php find_selected_news_page(); ?>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Washington Jesuit Adacemy: A high quality and comprehensive middle school for 5th through 8th grade boys from low-income communities in the DC metro area.">
<meta name="keywords" content="">
<meta name="author" content="Washington Jesuit Academy">
<title>Washington Jesuit Academy: About</title>
<link rel="stylesheet" type="text/css" href="https://cloud.typography.com/6113114/6497572/css/fonts.css"/>
<link rel="stylesheet" type="text/css" href="https://cloud.typography.com/683054/7063952/css/fonts.css"/>
<link href="/assets/css/wja.css" rel="stylesheet" type="text/css">
<link href="/assets/css/wja-startup.css" rel="stylesheet">
</head>
<body>
<?php include($_SERVER['DOCUMENT_ROOT']."/includes/navigation.php");?>
<script src="//cdn.tinymce.com/4/tinymce.min.js"></script>
<script type="text/javascript">
tinymce.init({
selector: 'textarea',
theme: 'modern',
plugins: [
'advlist autolink link image lists charmap print preview hr anchor pagebreak spellchecker',
'searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking',
'save table contextmenu directionality template paste textcolor'
],
content_css: 'css/content.css',
menubar: 'edit view format',
toolbar: 'removeformat | bold italic | bullist numlist outdent indent | link anchor | nonbreaking charmap hr | print preview fullpage | code'
});
</script>
<div class="content">
<div class="block">
<div class="container">
<div id="col-md-12"> <?php echo message(); ?> <?php echo form_errors($errors); ?>
<h2>New article or news item</h2>
<form action="create_news.php" method="post" class="form-horizontal" enctype="multipart/form-data">
<div class="form-group">
<label for="visible" class="col-sm-2 control-label">Published</label>
<div class="col-sm-10">
<label class="radio-inline">
<input type="radio" name="visible" id="visible1" value="N" checked>
No </label>
<label class="radio-inline">
<input type="radio" name="visible" id="visible2" value="Y">
Yes </label>
<p class="small">If ‘Yes’ is selected, the item will be publicly visible on the website as soon as it is saved.</p>
</div>
</div>
<div class="form-group">
<label for="homepage" class="col-sm-2 control-label">Featured on Homepage</label>
<div class="col-sm-10">
<label class="radio-inline">
<input type="radio" name="homepage" id="homepage1" value="N" checked>
No </label>
<label class="radio-inline">
<input type="radio" name="homepage" id="homepage2" value="Y">
Yes </label>
<p class="small">If ‘Yes’ is selected, the item will also be featured on the <strong>homepage</strong>.</p>
</div>
</div>
<div class="form-group">
<label for="type" class="col-sm-2 control-label">Type</label>
<div class="col-sm-10">
<label class="radio-inline">
<input type="radio" name="type" id="type1" value="N" checked>
News </label>
<label class="radio-inline">
<input type="radio" name="type" id="type2" value="A">
President's Blog </label>
</div>
</div>
<div class="form-group">
<label for="publication_name" class="col-sm-2 control-label">Publication Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="publication_name" value="" />
</div>
</div>
<div class="form-group">
<label for="publication_url" class="col-sm-2 control-label">Publication URL</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="publication_url" value="" />
</div>
</div>
<div class="form-group">
<label for="month" class="col-sm-2 control-label">Month</label>
<div class="col-sm-10">
<select class="form-control" name="month">
<option value="">Select Month</option>
<option value="January">January</option>
<option value="February">February</option>
<option value="March">March</option>
<option value="April">April</option>
<option value="May">May</option>
<option value="June">June</option>
<option value="July">July</option>
<option value="August">August</option>
<option value="September">September</option>
<option value="October">October</option>
<option value="November">November</option>
<option value="December">December</option>
</select>
</div>
</div>
<div class="form-group">
<label for="date" class="col-sm-2 control-label">Date</label>
<div class="col-sm-10">
<select class="form-control" name="date">
<option value="">Select Date</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="08">8</option>
<option value="09">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
</div>
</div>
<div class="form-group">
<label for="year" class="col-sm-2 control-label">Year</label>
<div class="col-sm-10">
<select class="form-control" name="year">
<option value="">Select Year</option>
<option value="2000">2000</option>
<option value="2001">2001</option>
<option value="2002">2002</option>
<option value="2003">2003</option>
<option value="2004">2004</option>
<option value="2005">2005</option>
<option value="2006">2006</option>
<option value="2007">2007</option>
<option value="2008">2008</option>
<option value="2009">2009</option>
<option value="2010">2010</option>
<option value="2011">2011</option>
<option value="2012">2012</option>
<option value="2013">2013</option>
<option value="2014">2014</option>
<option value="2015">2015</option>
<option value="2016">2016</option>
<option value="2017">2017</option>
<option value="2018">2018</option>
<option value="2019">2019</option>
<option value="2020">2020</option>
</select>
</div>
</div>
<div class="form-group">
<label for="title" class="col-sm-2 control-label">Title</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="title" value="" />
</div>
</div>
<div class="form-group">
<label for="author" class="col-sm-2 control-label">Author</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="author" value="" />
<p class="small">If this is a President’s Blog, type <strong>Bill Whitaker, Founding President</strong></p>
</div>
</div>
<div class="form-group margin-t-25">
<label for="summary" class="col-sm-2 control-label">Summary</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="summary" value="" />
</div>
</div>
<div class="form-group margin-t-25">
<label for="full_text" class="col-sm-2 control-label">Full Text</label>
<div class="col-sm-10">
<textarea name="full_text" rows="10" style="width:100%"></textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Optional Tag(s)</label>
<div class="col-sm-5">
<label class="checkbox m-l">
<input type="checkbox" name="tag_1" value="Y">
Tag 1 </label>
<label class="checkbox m-l">
<input type="checkbox" name="tag_2" value="Y">
Tag 2 </label>
<label class="checkbox m-l">
<input type="checkbox" name="tag_3" value="Y">
Tag 3 </label>
<label class="checkbox m-l">
<input type="checkbox" name="tag_4" value="Y">
Tag 4 </label>
</div>
<div class="col-sm-5">
<label class="checkbox m-l">
<input type="checkbox" name="tag_5" value="Y">
Tag 5 </label>
<label class="checkbox m-l">
<input type="checkbox" name="tag_6" value="Y">
Tag 6</label>
<label class="checkbox m-l">
<input type="checkbox" name="tag_7" value="Y">
Tag 7</label>
</div>
</div>
<div class="form-group"><hr />
<label for="full_text" class="col-sm-2 control-label">Image Upload </label>
<div class="col-sm-10">
<input type="file" name="image" class="mt-3"/>
</div> </div>
<div class="form-group"><hr />
<label for="full_text" class="col-sm-2 control-label">File Upload </label>
<div class="col-sm-10">
<input type="file" name="file" class="mt-3"/>
</div> </div>
<div class="text-right">
<input type="submit" name="submit" class="btn btn-primary m-t-md m-r" value="Create item" />
Cancel</div>
</form>
</div>
</div>
</div>
<?php include($_SERVER['DOCUMENT_ROOT']."/includes/footer.php");?>
<!-- JavaScript -->
<script src="../assets/js/jquery.min.js"></script>
<script src="../assets/js/toolkit.js"></script>
<script src="../assets/js/application.js"></script>
</div>
</body></html><?php
// Close database connection
if (isset($connection)) {
mysqli_close($connection);
}
?>
And here is my "create" page:
<?php require_once($_SERVER['DOCUMENT_ROOT']."/includes/session.php");?>
<?php require_once($_SERVER['DOCUMENT_ROOT']."/includes/db_connection.php");?>
<?php
session_start();
if($_SESSION["login_user"] != true) {
echo("Access denied!");
exit();
}
?>
<?php require_once($_SERVER['DOCUMENT_ROOT']."/includes/functions.php");?>
<?php require_once($_SERVER['DOCUMENT_ROOT']."/includes/validation_functions.php");?>
<?php
if (isset($_POST['submit'])) {
// Process the form
$visible = mysql_prep($_POST["visible"]);
$homepage = mysql_prep($_POST["homepage"]);
$type = mysql_prep($_POST["type"]);
$publication_name = mysql_prep($_POST["publication_name"]);
$publication_url = mysql_prep($_POST["publication_url"]);
$month = mysql_prep($_POST["month"]);
$date = mysql_prep($_POST["date"]);
$year = mysql_prep($_POST["year"]);
$title = mysql_prep($_POST["title"]);
$author = mysql_prep($_POST["author"]);
$summary = mysql_prep($_POST["summary"]);
$full_text = mysql_prep($_POST["full_text"]);
$tag_1 = mysql_prep($_POST["tag_1"]);
$tag_2 = mysql_prep($_POST["tag_2"]);
$tag_3 = mysql_prep($_POST["tag_3"]);
$tag_4 = mysql_prep($_POST["tag_4"]);
$tag_5 = mysql_prep($_POST["tag_5"]);
$tag_6 = mysql_prep($_POST["tag_6"]);
$tag_7 = mysql_prep($_POST["tag_7"]);
$image = rand(1000,100000)."-".$_FILES['image']['name'];
$image_loc = $_FILES['image']['tmp_name'];
$image_size = $_FILES['image']['size'];
$image_type = $_FILES['image']['type'];
$image_folder="images/";
$file = rand(1000,100000)."-".$_FILES['file']['name'];
$file_loc = $_FILES['file']['tmp_name'];
$file_size = $_FILES['file']['size'];
$file_type = $_FILES['file']['type'];
$file_folder="files/";
$image_new_size = $image_size/1024;
$file_new_size = $file_size/1024;
$new_image_name = strtolower($image);
$new_file_name = strtolower($file);
$final_image=str_replace(' ','-',$new_image_name);
$final_file=str_replace(' ','-',$new_file_name);
if(move_uploaded_file($image_loc,$image_folder.$final_image))
if(move_uploaded_file($file_loc,$file_folder.$final_file))
$query = "INSERT INTO `news` (";
$query .= "visible, homepage, type, publication_name, publication_url, month, date, year, title, author, summary, full_text, tag_1, tag_2, tag_3, tag_4, tag_5, tag_6, tag_7, image, image_type, image_size, file, file_type, file_size ";
$query .= ") VALUES (";
$query .= " '{$visible}', '{$homepage}', '{$type}', '{$publication_name}', '{$publication_url}', '{$month}', '{$date}', '{$year}', '{$title}', '{$author}', '{$summary}', '{$full_text}', '{$tag_1}', '{$tag_2}', '{$tag_3}', '{$tag_4}', '{$tag_5}', '{$tag_6}', '{$tag_7}', '{$final_image}','{$image_type}','{$image_new_size}', '{$final_file}','{$file_type}','{$file_new_size}'";
$query .= ")";
$result = mysqli_query($connection, $query);
if ($result) {
// Success
$_SESSION["message"] = "Item created.";
redirect_to("manage_content.php");
} else {
// Failure
//$_SESSION["message"] = "Item creation failed.";
//redirect_to("new_news.php");
echo "Error: " . $query . "<br>" . $result->error;
}
} else {
// This is probably a GET request
redirect_to("new_news.php");
}
?>
<?php
if (isset($connection)) { mysqli_close($connection); }
?>
Currently I have created a form on a PHP form that posts to the send PHP code. All of the textareas/fields ETC work fine. The issue I have is that I have 3 file fields. The aim is to add 3 file attachments to the email. I just cant work out how to do it.
(Attachment areas at the bottom of the form)
<form method="post" action="quote_send.php">
<form class="form-light mt-20" role="form">
<div class="form-group">
<label>Title</label><br />
<select name="Title">
<option value="Mr">Mr</option>
<option value="Mrs">Mrs</option>
<option value="Miss">Miss</option>
<option value="Ms">Ms</option>
</select>
</div> <div class="row">
<div class="col-md-6">
<div class="form-group">
<label>Forename</label>
<input type="text" class="form-control" name="forename" placeholder="Your Forename">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Surname</label>
<input type="text" class="form-control" name="surname" placeholder="Your Surname">
</div>
</div>
</div>
<!----CONTACT DETAILS------>
<h3>Your Contact Details</h3>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label>Email Address</label>
<input type="text" class="form-control" name="visitormail" placeholder="Your Email Address">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Contact Number</label>
<input type="text" class="form-control" name="number" placeholder="Your Contact Number">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Address Line 1</label>
<input type="text" class="form-control" name="address1" placeholder="Address Line 1">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Address Line 2</label>
<input type="text" class="form-control" name="address2" placeholder="Address Line 2">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>City</label>
<input type="text" class="form-control" name="city" placeholder="City">
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<label>Post Code</label>
<input type="text" class="form-control" name="pcode" placeholder="Post Code">
</div>
</div>
</div>
<!----SITE DETAILS----->
<h3>Site Contact Details</h3>
<div class="form-group">
<label>Title</label><br />
<select name="siteTitle">
<option value="Mr">Mr</option>
<option value="Mrs">Mrs</option>
<option value="Miss">Miss</option>
<option value="Ms">Ms</option>
</select>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label>Site Contact Forename</label>
<input type="text" class="form-control" name="scforename" placeholder="Site Contact Forename">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Site Contact Surname</label>
<input type="text" class="form-control" name="scsurname" placeholder="Site Contact Surname">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Email Address</label>
<input type="text" class="form-control" name="scvisitormail" placeholder="Site Email Address">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Contact Number</label>
<input type="text" class="form-control" name="scnumber" placeholder="Site Contact Number">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Address Line 1</label>
<input type="text" class="form-control" name="scaddress1" placeholder="Site Address Line 1">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Address Line 2</label>
<input type="text" class="form-control" name="scaddress2" placeholder="Site Address Line 2">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>City</label>
<input type="text" class="form-control" name="sccity" placeholder="City">
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<label>Post Code</label>
<input type="text" class="form-control" name="scpcode" placeholder="Post Code">
</div>
</div>
</div>
<!----SITE DETAILS----->
<h3>Site Details</h3>
<div class="row">
<div class="col-md-2">
<div class="form-group">
<label>Number of Domestic Plots</label><br />
<select name="numdp">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5+">5+</option>
</select></div></div>
<div class="col-md-2">
<div class="form-group">
<label>Number of Commercial Plots</label><br />
<select name="numcp">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5+">5+</option>
</select>
</div></div>
<div class="col-md-2">
<div class="form-group">
<label>Is The Site Visit Required?</label><br />
<select name="sitevisitr">
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
</div></div>
<div class="col-md-3">
<div class="form-group">
<label>Is The Site a Brownfield/Regeneration?</label><br />
<select name="brownregen">
<option value="Brownfield">Brownfield</option>
<option value="Regeneration">Regeneration</option>
</select>
</div></div>
<div class="col-md-3">
<div class="form-group">
<label>Is The Site Contaminated?</label><br />
<select name="contam">
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
</div></div>
<div class="col-md-2">
<div class="form-group">
<label>Property Type</label><br />
<select name="proptype">
<option value="Commercial">Commercial</option>
<option value="Flat">Flat</option>
<option value="Detached">Detached</option>
<option value="Semi-Detached">Semi-Detached</option>
<option value="Terraced">Terraced</option>
</select>
</div></div>
<div class="col-md-2">
<div class="form-group">
<label>Rooms In The Property</label><br />
<select name="nrooms">
<option value="N/A">N/A</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10+">10+</option>
</select>
</div></div>
<div class="col-md-2">
<div class="form-group">
<label>Do You Have A Gas Supplier? *</label><br />
<select name="gsupplier">
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
</div></div>
<div class="col-md-3">
<div class="form-group">
<label>If Yes. Who Is Your Gas Supplier?</label>
<input type="text" class="form-control" name="gsuppliername" placeholder="Gas Supplier">
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>Who Will Be Carrying Out The Excavation?</label><br />
<select name="erxcav">
<option value="MDL">MDL</option>
<option value="Customer">Customer</option>
</select>
</div></div>
<br /><p> * NOTE: If you do not have a gas supplier in place, you will need to obtain one before any works can be carried out. You can find a gas supplier here.</p>
<div class="col-md-2">
<div class="form-group">
<label>What Service Do You Require?</label><br />
<select name="servicer">
<option value="Gas Connection(s)">Gas Connection(s)</option>
<option value="Gas Disconnection(s)">Gas Disconnection(s)</option>
<option value="Meter Fitting / Exchange">Meter Fitting / Exchange</option>
<option value="Directional Drilling">Directional Drilling</option>
<option value="Outlet Pipework">Outlet Pipework</option>
</select>
</div></div>
<div class="col-md-3">
<div class="form-group">
<label>What Is Your Hourly Load? (KWh)</label>
<input type="text" class="form-control" name="hourl" placeholder="Hourly Load (KWh)">
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>What Is Your Annual Load? (KWh)</label>
<input type="text" class="form-control" name="annl" placeholder="Annual Load? (KWh)">
</div>
</div> <br /><br /><br /><br />
<p> * NOTE: We require specific documents so we can proceed with your quote. These documents can be seen in the upload section below</p>
<div class="col-md-4">
<div class="form-group">
<label>Scaled Site Location Plan</label>
<input name="sslp" type="file">
</div></div>
<div class="col-md-4">
<div class="form-group">
<label>Domestic Property Schedule</label>
<input name="dps" type="file">
</div></div>
<div class="col-md-4">
<div class="form-group">
<label>Site Boundary Drawing</label>
<input name="sbd" type="file">
</div></div>
<p> * NOTE: We require specific documents so we can proceed with your quote. These documents can be seen in the upload section below</p>
<div class="col-md-6">
<div class="form-group">
<label>Is There Any Other Information You Think Would Help Us?</label><br />
<textarea class="form-control" name="notes" placeholder="Write you message here..." style="height:100px;"></textarea>
</div></div>
</div>
<br / >
<button type="submit" class="btn btn-two">SUBMIT</button>
</form>
THE PHP send code.-----------------------
<?php
$Title = $_POST['Title'];
$forename = $_POST['forename'];
$surname = $_POST['surname'];
$visitormail = $_POST['visitormail'];
$number = $_POST['number'];
$address1 = $_POST['address1'];
$address2 = $_POST['address2'];
$city = $_POST['city'];
$pcode = $_POST['pcode'];
$siteTitle = $_POST['siteTitle'];
$scforename = $_POST['scforename'];
$scsurname = $_POST['scsurname'];
$scvisitormail = $_POST['scvisitormail'];
$scnumber = $_POST['scnumber'];
$scaddress1 = $_POST['scaddress1'];
$scaddress2 = $_POST['scaddress2'];
$sccity = $_POST['sccity'];
$scpcode = $_POST['scpcode'];
$numdp = $_POST['numdp'];
$numcp = $_POST['numcp'];
$sitevisitr = $_POST['sitevisitr'];
$brownregen = $_POST['brownregen'];
$contam = $_POST['contam'];
$proptype = $_POST['proptype'];
$nrooms = $_POST['nrooms'];
$gsupplier = $_POST['gsupplier'];
$gsuppliername = $_POST['gsuppliername'];
$erxcav = $_POST['erxcav'];
$servicer = $_POST['servicer'];
$hourl = $_POST['hourl'];
$annl = $_POST['annl'];
$notes = $_POST['notes'];
$attn = $_POST['attn'];
$sslp = $_POST['sslp'];
$dps = $_POST['dps'];
$sbd = $_FILES['sbd'];
if (eregi('http:', $notes)) {
die ("Do NOT try that! ! ");
}
if(!$visitormail == "" && (!strstr($visitormail,"#") || !strstr($visitormail,".")))
{
echo "<h2>Use Back - Enter valid e-mail</h2>\n";
$badinput = "<h2>Feedback was NOT submitted</h2>\n";
echo $badinput;
die ("Go back! ! ");
}
if(empty($forename) || empty($visitormail) || empty($notes )) {
echo "<h2>You have missed out required fields, please go back to them and fill them in</h2>\n";
die ("Use back! ! ");
}
$todayis = date("l, F j, Y, g:i a") ;
$attn = $attn ;
$subject = "New $servicer Quote Request";
$notes = stripcslashes($notes);
$message = "Section 1 - Customer Details \n
Customer Title: $Title
Customer Forname: $forename
Customer Surname: $surname
Customer Email: $visitormail
Customer Contact Number: $number
Contact Postal Address:\n $address1 \n $address2 \n $city \n $pcode \n
Section 2 - Site Contact Details \n
Site Contact Title: $siteTitle
Site Contact Forname: $scforename
Site Contact Surname: $scsurname
Site Contact Email Address: $scvisitormail
Site Contact Number: $scnumber
Site Current Postal Address:\n $scaddress1 \n $scaddress2 \n $sccity \n $scpcode \n
Section 3 - Site Work Details \n
Number of Domestic Plots: $numdp
Number of Commercial Plots: $numcp
Site Visit Required: $sitevisitr
Site a Brownfield/Regeneration: $brownregen
Site Contaminated: $contam
Property Type: $proptype
Number of Rooms in The Property: $nrooms
Gas Supplier Organised: $gsupplier
Gas Supplier Name: $gsuppliername
Who Will Be Carrying Out The Excavation: $erxcav
Service Rquired: $servicer
Hourly Load: $hourl
Annual Load: $annl
Extra Information: $notes
Attached Files: $sslp \n $dps \n $sbd
Please reply to this email within 24 hours to maximise our chances of turning enquiries in to sales.
";
$_FILES ="$sbd";
$from = "From: $visitormail\r\n";
mail("ash.manterfield#btinternet.com", $subject, $message, $from, $_FILES);
?>
</span>Thank you <?php echo $visitor ?> for contacting us regarding <?php echo $attn ?>.
Any help would be appreciated I've tried a few approaches and cant work out how to do it.