I need a little help or advice. I create advanced storing form in PHP PDO. Form must have upload post image ( header image ) and gallery images ( multi image store into database in same database ). I have done with store single image into database, but im stuck with multi store images into same database. I will put my code here.
<?php require('includes/config.php');
//if not logged in redirect to login page
if(!$user->is_logged_in()){ header('Location: index.php'); }
// Upload posted information
include('core/connection.php');
include('functions/main.php');
if($_POST){
$nameproduct = $_POST['nameProduct'];
$categoryproduct = $_POST['categoryProduct'];
$keywordproduct = $_POST['keywordProduct'];
$addressproduct = $_POST['addressProduct'];
$latproduct = $_POST['latProduct'];
$lonproduct = $_POST['lonProduct'];
$locationproduct = $_POST['locationProduct'];
$telproduct = $_POST['telProduct'];
$emailproduct = $_POST['emailProduct'];
$siteproduct = $_POST['siteProduct'];
$pdate = date("Y-m-d H:i:s");
if(empty($nameproduct) or empty($keywordproduct)){
$errors = '<div class="error2"><p> All fields are required. Please try again</p></div>';
}else{
if (isset($_FILES['post_image'])===true) {
if (empty($_FILES['post_image']['name']) ===true) {
$errors = '<div class="error2">Please Choose a Post Image</div>';
}else {
$allowed = array('jpg','jpeg','gif','png');
$file_name = $_FILES['post_image']['name'];
$file_extn = strtolower(end(explode('.', $file_name)));
$file_temp = $_FILES['post_image']['tmp_name'];
if (in_array($file_extn, $allowed)===true) {
$file_parh = 'images/' . substr(md5(time()), 0, 10).'.'.$file_extn;
move_uploaded_file($file_temp, $file_parh);
$query = $pdo->prepare("INSERT INTO `go-wp`.`products` (`post_id`, `nameProduct`, `categoryProduct`, `keywordProduct`, `addressProduct`, `latProduct`, `lonProduct`, `locationProduct`, `telProduct`, `emailProduct`, `siteProduct`, `post_date`, `post_image`) VALUES (NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
$query->bindValue(1, $nameproduct);
$query->bindValue(2, $categoryproduct);
$query->bindValue(3, $keywordproduct);
$query->bindValue(4, $addressproduct);
$query->bindValue(5, $latproduct);
$query->bindValue(6, $lonproduct);
$query->bindValue(7, $locationproduct);
$query->bindValue(8, $telproduct);
$query->bindValue(9, $emailproduct);
$query->bindValue(10, $siteproduct);
$query->bindValue(11, $pdate);
$query->bindValue(12, $file_parh);
$query->execute();
header('Location: view_product.php');
}
}
}
}
}
?>
Code above present store single image into database ( works nice ). But when i add into HTML code next code ( below ) i have problems. What to write, how to create nice script. I open form html <form action="" method="post" enctype="multipart/form-data">
<div class="col-md-4">
<div class="act-widget fl-wrap">
<div class="profile-edit-header fl-wrap">
<h4>Gallery product</h4>
</div>
<div class="add-list-media-wrap fuzone">
<div class="fu-text">
<span><i class="fa fa-picture-o"></i> Add multiple images</span>
</div>
<input class="input-group" class="upload" type="file" name="post_image" id="imgInput" />
</div>
</div>
</div>
Full HTML code looks like this:
<form action="" method="post" enctype="multipart/form-data">
<div class="profile-edit-container add-list-container">
<div class="profile-edit-header fl-wrap">
<h4>Information product</h4>
</div>
<div class="custom-form">
<label>Product name<i class="fa fa-briefcase"></i></label>
<input type="text" name="nameProduct" placeholder="Product name" value=""/>
<div class="row">
<div class="col-md-6">
<label>Category</label>
<select name="categoryProduct" data-placeholder="Select product category:" class="chosen-select">
<option value="Choose category" selected>Choose category:</option>
<option value="Category1">Category1</option>
<option value="Category2">Category2</option>
<option value="Category3">Category3</option>
<option value="Category4">Category4</option>
</select>
</div>
<div class="col-md-6">
<label>Keywords<i class="fa fa-key"></i></label>
<input type="text" name="keywordProduct" placeholder="Max 5 keywords" value=""/>
</div>
</div>
</div>
</div>
<div class="profile-edit-container add-list-container">
<div class="profile-edit-header fl-wrap">
<h4>Product location</h4>
</div>
<div class="custom-form">
<label>Address<i class="fa fa-map-marker"></i></label>
<input type="text" name="addressProduct" placeholder="Address" value=""/>
<div class="row">
<div class="col-md-6">
<label>Latitude:<i class="fa fa-map-marker"></i></label>
<input type="text" name="latProduct" id="lat" placeholder="Latitude" value=""/>
</div>
<div class="col-md-6">
<label>Longitude:<i class="fa fa-map-marker"></i></label>
<input type="text" name="lonProduct" id="long" placeholder="Longitude" value=""/>
</div>
</div>
<div class="map-container">
<div id="singleMap" data-latitude="40.7427837" data-longitude="-73.11445617675781"></div>
</div>
<label>Location</label>
<select name="locationProduct" data-placeholder="Location" class="chosen-select" >
<option value="Choose location" selected>Choose location:</option>
<option value="Location1">Location1</option>
<option value="Location2">Location2</option>
<option value="Location3">Location3</option>
<option value="Location4">Location4</option>
<option value="Location5">Location5</option>
<option value="Location6">Location6</option>
</select>
<label>Phone<i class="fa fa-phone"></i></label>
<input type="text" name="telProduct" placeholder="Phone" value=""/>
<label>Email<i class="fa fa-envelope-o"></i></label>
<input type="text" name="emailProduct" placeholder="Email" value=""/>
<label>Site<i class="fa fa-globe"></i></label>
<input type="text" name="siteProduct" placeholder="Site" value=""/>
</div>
</div>
<div class="col-md-4">
<div class="act-widget fl-wrap">
<div class="profile-edit-header fl-wrap">
<h4>Header image</h4>
</div>
<div class="add-list-media-wrap fuzone">
<div class="fu-text">
<span><i class="fa fa-picture-o"></i> Add header image</span>
</div>
<input class="input-group" class="upload" type="file" name="post_image" id="imgInput" />
</div>
</div>
</div>
<div class="col-md-4">
<div class="act-widget fl-wrap">
<div class="profile-edit-header fl-wrap">
<h4>Gallery image</h4>
</div>
<div class="add-list-media-wrap fuzone">
<div class="fu-text">
<span><i class="fa fa-picture-o"></i> Add gallery images</span>
</div>
<input class="input-group" class="upload" type="file" name="post_image" id="imgInput" />
</div>
</div>
</div>
<div class="custom-form">
<button name="submit" class="btn big-btn color-bg flat-btn">Add product<i class="fa fa-angle-right"></i></button>
</div>
</form>
How to generate code for storing multy images into database with this code. Thanks all
Related
I am having issues adding some data to my DB. Down below I will post my code so far, there is something I'm probably missing but i don't understand what exactly.
I'm running this on my localhost using PHP 7.0.9 but I don't think that matters.
This is on the Profile Page:
<form method="post">
<div class="row-form">
<div class="col-lg-14"><strong>Title:</strong></div>
<div class="col-md-18"><input type="text" class="form-control" name="title"/></div>
</div>
<br>
<div class="row-form">
<div class="col-lg-14"><strong>Content:</strong></div>
<div class="col-md-18"><input type="text" class="form-control" name="content"/></div>
</div>
<br>
<div class="row-form">
<div class="col-md-14"><strong>Time:</strong></div>
<div class="col-md-18"><input type="text" class="form-control" name="time1"/></div>
</div>
<br>
<div class="row-form">
<div class="col-md-14"><strong>Date:</strong></div>
<div class="col-md-18"><input type="text" class="form-control" name="date1"/></div>
</div>
<div class="row-form">
<div class="col-md-18"><input type="hidden" class="form-control" name="author" value="<?php echo $_SESSION['username']; ?>" /></div>
</div>
<br>
<button name="addDates" class="btn btn-success">Submit</button>
</form>
And here's my PHP code :
<form method="POST">
<?php
require '#/config.php';
if (isset($_POST['addDates']))
{
if (empty($_POST['title']) || empty($_POST['content']) || empty($_POST['time1']) || empty($_POST['date1']) || empty($_POST['author']))
{
$error = 'Please verify all fields';
}
if (empty($error))
{
$SQLinsert = $odb -> prepare("INSERT INTO `dates` VALUES(NULL, :title, :content, :time1, :date1, UNIX_TIMESTAMP(), :author)");
$SQLinsert -> execute(array(':title' => $_POST['title'], ':content' => $_POST['content'], ':time1' => $_POST['time1'], ':date1' => $_POST['date1'], ':author' => $_POST['author']));
echo success('Date has been added');
}
else
{
echo error($error);
}
}
?>
</form>
Once i fill the forms and submit the page just refresh but nothing has been added on my side.
I am trying to send multiple files in one request using DropZone js.
<script type="text/javascript">
Dropzone.autoDiscover = false;
var file= new Dropzone(".dropzone",{
url: any url,
method:"post",
paramName:"PhotoFiles",
addRemoveLinks:true,
autoProcessQueue: false
});
//Upload file onsubmit
$('#UploadMultiFiles').submit(function(){
file.processQueue();
});
file.on("sending",function(a,b,c){
a.token=Math.random();
c.append("token",a.token);
});
The issue is I have other inputs in the same form that is why I used onsubmit, and these inputs are saved in a table and the images from dropzone are saved in another table with and both tables have one to many relationship
The Controller like:
public function university_offers($id){
$data['university_offer_name']=$this->input->post('university_offer_name');
$data['university_id_fk']=$this->input->post('university_id_fk');
$data['university_offer_details']=$this->input->post('university_offer_details');
if ($this->input->post('save')){
$data2['university_offer_id_fk'] = insertrecords('university_offers',$data);
$data2['university_id_fk'] = $data['university_id_fk'];
//when I put the next IF at the begining of the function it works but ofcourse without the other data fields that I need.
if(isset($_FILES) && $_FILES != null){
$data2['photo_name'] = upload_image('PhotoFiles');
insertrecords('university_offer_photos',$data2);
}
if (insertrecords('university_offer_photos',$data2)==true)
message('success','');
redirect('Admin/university_offers/0','refresh');
}
$data['view']="admin/universities/university_offers";
$this->load->view('index',$data);
}
What I need is sending al uploaded files and do a loop in the controller to save it right in the database, not sending each file to the controller and saving it.
Edit:
My view is like:
<form action="university_offers/<?=$id?>" id="UploadMultiFiles" autocomplete="off" method="post" enctype="multipart/form-data" class="m-t-5" novalidate>
<div class="form-body">
<h3 class="card-title">بيانات العرض</h3>
<hr>
<div class="row p-t-20">
<div class="col-md-6">
<div class="form-group">
<label class="control-label">إسم العرض<span class="text-danger">*</span></label>
<div class="controls">
<input type="text" autocomplete="off" name="university_offer_name" class="form-control" required value="<?php if(isset($result)) echo $result['university_offer_name']?>" data-validation-required-message="يجب إدخال إسم العرض" placeholder="إسم العرض">
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label class="control-label">إسم الجامعة<span class="text-danger">*</span></label>
<div class="controls">
<select name="university_id_fk" id="select" class="form-control" required data-validation-required-message="يجب إختيار الجامعة" aria-invalid="false">
<option value="">إختر الجامعة</option>
<?php
foreach (selectrecords("*",'universities') as $university):
$select = '';
if(isset($result) && $result['university_id_fk'] == $university->university_id_pk)
$select = 'selected';
?>
<option <?=$select?> value="<?php echo $university->university_id_pk ?>"><?php echo $university->university_name ?></option>
<?php endforeach;?>
</select>
</div>
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<label class="control-label">تفاصيل العرض<span class="text-danger">*</span></label>
<div class="controls">
<textarea id="mymce" name="university_offer_details"><?php if(isset($result)) echo $result['university_offer_details'] ?></textarea>
</div>
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<label class="control-label">صور العرض<span class="text-danger">*</span></label>
<div class="row">
<?php
if(isset($result)) {
foreach (selectrecords('*','university_offer_photos',array('university_offer_id_fk'=>$result['university_offer_id_pk'])) as $photo):
echo'
<div class="form-group text-center" id="'.$photo->photo_id_pk.'">
<div class="col-md-12">
<img style="border: none; height: 150px; width: 150px; border-radius: 10px;" class="img-thumbnail" src="'.base_url().'public/uploads/images/'.$photo->photo_name.'">
</div>
حذف الملف
</div>
';
endforeach;
}
?>
</div>
<div class="dropzone">
<div class="dz-message">
<span> Drag and Drop your files here Or Click here to upload</span>
</div>
</div>
</div>
</div>
</div>
<div class="form-actions">
<input type="hidden" id="url" value="university_offers/<?=$id?>" />
<?php
if($id == 0)
echo '<button type="submit" id="butt" name="save" value="save" class="btn btn-primary"> <i class="fa fa-check"></i> حفظ</button>';
else
echo '<button type="submit" id="butt" name="edit" value="edit" class="btn btn-primary"><i class="fa fa-check"></i> حفظ</button>';
?>
<button type="reset" class="btn btn-inverse"><i class="fa fa-times"></i> إلغاء</button>
<?php
if($id == 0)
echo'<button type="button" id="backword" class="btn btn-second"><i class="fa fa-undo"></i> رجوع</button>';
else{
echo '<input type="hidden" name="university_offer_id_pk" value="'.$result['university_offer_id_pk'].'"/>
<button type="button" class="btn btn-second"><i class="fa fa-undo"></i> رجوع</button>';
}
?>
</div>
</div>
</form>
upload_image function, I put it in the Helper
function upload_image($file_name){
$CI =& get_instance();
$config['upload_path'] = 'public/uploads/images';
$config['allowed_types'] = 'gif|Gif|ico|ICO|jpg|JPG|jpeg|JPEG|BNG|png|PNG|bmp|BMP|WMV|wmv|MP3|mp3|FLV|flv|SWF|swf';
$config['max_size'] = '1024*8';
$config['encrypt_name']=true;
$CI->load->library('upload',$config);
if(! $CI->upload->do_upload($file_name)){
return false;
}else{
$datafile = $CI->upload->data();
thumb($datafile);
watermark($datafile);
return $datafile['file_name'];
}}
Hi I'm working on a real estate project. I have a form which has some inputs & then 3 forms incorporated in the 1st form which have the dropzone class for a simple picture, a picture gallery & pdf files. I tried a lot of techniques but couldn't get the dropzones to work with the main form.
My Issues:
Dropzone sends the inputs & picture before submit button gets hit.
If after that, the submit button gets clicked then some inputs get null & 2 records get inserted.
If I remove or hide the submit button or change it to anchor tag for redirecting then the picture doesn't get uploaded.
Listings_controller:
function insert_listing(){
$pass = rand(0,999);
$data_seller = array(
'name' => $this->input->post('name'),
'email' => $this->input->post('email'),
'cell' => $this->input->post('cell'),
'sms' => $this->input->post('sms'),
'pass' => MD5($pass),
'status' => 'seller',
'last_date' => date('Y-m-d')
);
$result1 = $this->users_model->add_seller($data_seller);
$data_listing = array(
'code' => $this->input->post('code'),
'address' => $this->input->post('address'),
'city' => $this->input->post('city'),
'state' => $this->input->post('state'),
'zipcode' => $this->input->post('zipcode'),
'process' => $this->input->post('process'),
'step' => $this->input->post('step'),
'price' => $this->input->post('price'),
'agent_id' => $this->input->post('agent'),
'seller_id' => $this->db->insert_id()
);
$result2 = $this->listings_model->add_listing($data_listing);
if($result2){
$this->session->set_flashdata('success','Listing Added Successfully');
}else{
$this->session->set_flashdata('error','Listing Already Exists !');
}
//Dropzone - Pic
if(!empty($_FILES)){
$tempFile = $_FILES['file']['tmp_name'];
$fileName = substr(sha1(rand(000,9999)),0,7).$_FILES['file']['name'];
$targetPath = getcwd().'/assets/admin/images/image-gallery/';
$targetFile = $targetPath.$fileName;
move_uploaded_file($tempFile,$targetFile);
$listing_id = $result2['id'];
$data_listing_pic['listing_id'] = $listing_id;
$data_listing_pic['pic'] = $fileName;
$result3 = $this->listings_model->add_listing_pic($data_listing_pic);
}
redirect('admin/listings');
}
Users_model:
//Seller Add
function add_seller($data_seller){
//Check Duplicate
$this->db->select('*');
$this->db->from($this->table);
$this->db->where('email',$data_seller['email']);
$query = $this->db->get();
if($query->num_rows() > 0){
$seller_id = $query->result_array();
$data_seller['id'] = $seller_id[0]['id'];
//Update Info
$this->db->where('email',$data_seller['email']);
$this->db->update($this->table,$data_seller);
return $data_seller;
}else{
//INSERT Seller
$result = $this->db->insert($this->table,$data_seller);
//GET Last Inserted ID
$seller_id = $this->db->insert_id();
$data_seller['id'] = $seller_id;
return $data_seller;
}
}
Listings_model:
//Listing Add
function add_listing($data_listing){
$result = $this->db->insert($this->table,$data_listing);
$listing_id = $this->db->insert_id();
$data_listing['id'] = $listing_id;
return $data_listing;
}
//Listing Pic Add
function add_listing_pic($data_listing_pic){
$result = $this->db->insert($this->pics_table,$data_listing_pic);
return $result;
}
My View:
<form action="<?php echo base_url();?>admin/insert_listing" class="dropzone dz-clickable" method="POST" enctype="multipart/form-data">
<input type="hidden" name="code" value="<?php echo $listing_code; ?>" />
<div class="row">
<div class="col-lg-6">
<strong>Property Information:</strong>
<br><br>
<div class="form-group form-float form-group-lg">
<div class="form-line">
<input type="text" class="form-control" name="address" autofocus required />
<label class="form-label">Street Address:</label>
</div>
<br>
<div class="form-line">
<input type="text" class="form-control" name="city" required />
<label class="form-label">City/Town:</label>
</div>
<br>
<div class="form-line">
<input type="text" class="form-control" name="state" required />
<label class="form-label">State:</label>
</div>
<br>
<div class="form-line">
<input type="text" class="form-control" name="zipcode" required />
<label class="form-label">Zip Code:</label>
</div>
</div>
</div>
<div class="col-lg-6">
<strong>Seller Information:</strong>
<br><br>
<div class="form-group form-float form-group-lg">
<div class="form-line">
<input type="text" class="form-control" name="name" required />
<label class="form-label">Full Name(s):</label>
</div>
<br>
<div class="form-line">
<input type="email" class="form-control" name="email" required />
<label class="form-label">Seller's Email:</label>
</div>
<br>
<div class="form-line">
<input type="text" class="form-control" name="cell" required />
<label class="form-label">Cell Phone Number:</label>
</div>
<br>
<div class="demo-checkbox">
<input type="checkbox" id="md_checkbox_26" name="sms" class="filled-in chk-col-blue" checked />
<label for="md_checkbox_26">Send status updates via SMS</label>
</div>
</div>
</div>
</div>
<hr />
<div class="row">
<div class="col-lg-6">
<strong>Listing Agent:</strong>
<br /><br />
<select class="form-control show-tick" name="agent" required >
<option value="">-- Please choose from the drop down --</option>
<?php for($j=0; $j < count($agent_list); $j++){ ?>
<option value="<?php echo $agent_list[$j]['id']; ?>" ><?php echo $agent_list[$j]['name']; ?></option>
<?php } ?>
</select>
<br />
</div>
<div class="col-lg-6">
<strong>Listing Status Information:</strong>
<br /><br />
<select class="form-control show-tick" name="process" required >
<option value="">-- Please choose from the drop down --</option>
<option value="Listing Process">Listing Process</option>
</select>
<br /><br />
<select class="form-control show-tick" name="step" required >
<option value="">-- Please choose from the drop down --</option>
<option value="1">Step 1: The Prep</option>
<option value="2">Step 2: File Set Up</option>
<option value="3">Step 3: Pre-listing Checklists</option>
<option value="4">Step 4: Sign Installation</option>
<option value="5">Step 5: Feature Sheets</option>
<option value="6">Step 6: Open Houses</option>
<option value="7">Step 7: You Received an Offer!</option>
</select>
</div>
</div>
<hr />
<div class="row">
<div class="col-lg-12">
<strong>Photo and Price:</strong>
<br><br>
<div class="form-group form-float form-group-lg">
<div class="form-line">
<input type="text" class="form-control" name="price" required />
<label class="form-label">Listing Price: $</label>
</div>
</div>
<form action="<?php echo base_url();?>admin/insert_listing_pdf" id="PDFUpload" class="dropzone dz-clickable" method="POST" enctype="multipart/form-data">
<div class="dz-message">
<div class="drag-icon-cph">
<i class="material-icons">touch_app</i>
</div>
<h3>Drop the Photo here or Click to Upload.</h3>
<em>(It is recommended to upload the most attractive photo that will catch the user's eye)</em>
</div>
</form>
</div>
</div>
<hr />
<div class="row">
<div class="col-lg-6">
<strong>Upload Gallery Photos:</strong>
<br><br>
<form action="<?php echo base_url();?>admin/insert_listing_gallery" id="GalleryUpload" class="dropzone dz-clickable" method="POST" enctype="multipart/form-data">
<div class="dz-message">
<div class="drag-icon-cph">
<i class="material-icons">touch_app</i>
</div>
<h3>Drop files here or click to upload.</h3>
<em>(Upload all the gallery photos of the property in this section)</em>
</div>
</form>
</div>
<div class="col-lg-6">
<strong>Upload PDF Files:</strong>
<br><br>
<form action="<?php echo base_url();?>admin/insert_listing_pdf" id="PDFUpload" class="dropzone dz-clickable" method="POST" enctype="multipart/form-data">
<div class="dz-message">
<div class="drag-icon-cph">
<i class="material-icons">touch_app</i>
</div>
<h3>Drop files here or click to upload.</h3>
<em>(Upload all the PDF files related to the property in this section)</em>
</div>
</form>
</div>
</div>
<hr />
<div class="row">
<div class="col-lg-12">
<button type="submit" class="btn btn-primary btn-lg waves-effect">ADD LISTING</button>
</div>
</div>
</form>
I'm developing a script for online admission in a website. Below is php code of the page. The problem is that it's not submitting.
<?php
include ("include/header.php"), include ("include/config.php");
if(isset($_POST['applyAdmission'])) {
$admission_no = $_POST['admission_no'];
$f_name = $_POST['f_name'];
$l_name = $_POST['l_name'];
$p_add = $_POST['p_add'];
$c_add = $_POST['c_add'];
$dob = $_POST['dob'];
$education = $_POST['education'];
$mobile = $_POST['mobile_no'];
$course = $_POST['course'];
$subjects = $_POST['subjects'];
$timing = $_POST['timing'];
$filepath_pic = $_FILES['picture']['name'];
$res_move_pic = move_uploaded_file($_FILES['picture']['tmp_name'], "/admission/".$filepath_pic);
$filepath_sign = $_FILES['sign']['name'];
$res_move_sign = move_uploaded_file($_FILES['sign']['tmp_name'], "/admission/".$filepath_sign);
$agree_terms = $_POST['agree_terms'];
$agree_cond = $_POST['agree_cond'];
if ($res_move_pic == 1 && $res_move_sign == 1 ) {
$query = "INSERT into online_admission (f_name, l_name, p_add, c_add, dob, degree, mobile_no, course, subjects, timing, pic, sign, agree_terms, agree_cond, applied_on)
values ('$f_name','$l_name','$p_add','$c_add','$dob','$education','$mobile','$course','$subjects','$timing','$filepath_pic','$filepath_sign','$agree_terms','$agree_cond','now()')";
$res = mysql_query($query) or die("ERROR: Unable to insert into database.");
if ($res == 1) {
header('Location:http://adarshclasses.in/admission_success.php/');
exit();
} else {
header('Location:http://adarshclasses.in/admission_failed.php/');
exit();
}
} else {
echo "Error in updateing profile pic and sign";
}
} else {
//echo "Please submit the form, thanks!";
}
;?>
Everything in form is correct like I added same name in form which i used in $_POST but still it's not working, please help me to fix this issue.
Here is html codes of form:
<form class="form-horizontal" id="admission_form" method="post" action="" enctype="multipart/form-data">
<!--div class="row">
<div class="col-lg-6">
<label for="admission_no"> Admission No. </label>
<input type="hidden" class="form-control" name="admission_no" value="<?php echo $admission_no ;?>" readonly disabled>
</div>
</div--><br>
<div class="row">
<div class="col-lg-6">
<label for="f_name"> First Name <span class="required">*</span> </label>
<input type="text" class="form-control" name="f_name" placeholder="Your first name" value="<?php echo $f_name ;?>" required>
</div>
<div class="col-lg-6">
<label for="l_name"> Last Name <span class="required">*</span></label>
<input type="text" class="form-control" name="l_name" placeholder="Your last name" value="<?php echo $l_name ;?>" required>
</div>
</div><br>
<div class="row">
<div class="col-lg-12">
<label for="p_add"> Permanent Address <span class="required">*</span></label>
<textarea class="form-control" name="p_add" placeholder="Please write your permanent address" value="<?php echo $p_add ;?>" required></textarea>
</div>
</div><br>
<div class="row">
<div class="col-lg-12">
<label for="c_add"> Current Address in Jodhpur <span class="required">*</span></label>
<textarea class="form-control" name="c_add" placeholder="Please write your address where you currently living" value="<?php echo $c_add ;?>" required></textarea>
</div>
</div><br>
<div class="row">
<div class="col-lg-6">
<label for="dob"> Date of birth <span class="required">*</span></label>
<input type="date" class="form-control" name="dob" placeholder="Your date of birth eg:- 25/11/1996" value="<?php echo $dob ;?>" required>
</div>
<div class="col-lg-6">
<label for="education"> Recent passed degree/exam - </label>
<input type="text" class="form-control" name="education" placeholder="for example - BA/ B.Sc etc." value="<?php echo $education ;?>" >
</div>
</div><br>
<div class="row">
<div class="col-lg-6">
<label for="mobile_no"> Mobile Number <span class="required">*</span></label>
<input type="number" class="form-control" name="mobile_no" placeholder="Enter your mobile number, eg - 8384991980" value="<?php echo $mobile_no ;?>" required>
</div>
<div class="col-lg-6">
<label for="course"> Select course <span class="required">*</span> </label>
<select class="form-control" name="course" required>
<option value="none"> --- Select one course --- </option>
<option value="IAS"> IAS </option>
<option value="RAS"> RAS </option>
<option value="Police constable"> Police constable </option>
<option value="SI"> SI </option>
<option value="Railway"> Railway </option>
<option value="REET"> REET </option>
<option value="Teacher"> Teacher </option>
<option value="Patwar"> Patwar </option>
<option value="Bank PO"> Bank PO </option>
<option value="Jr Accountant"> Jr Accountant </option>
<option value="Rajasthan police"> Rajasthan police </option>
<option value="SSC (10+2)"> SSC (10+2) </option>
</select>
</div>
</div><br>
<div class="row">
<div class="col-lg-6">
<label for="subjects"> Subjects - </label>
<input type="text" class="form-control" name="subjects" placeholder="Enter your subject you want to read" value="<?php echo $subjects ;?>" required>
</div>
<div class="col-lg-6">
<label for="timing"> Classes Timing - </label>
<input type="text" class="form-control" name="timing" placeholder="Your preferred time for coaching" value="<?php echo $timing ;?>" required>
</div>
</div><br>
<div class="row">
<div class="col-lg-6">
<label for="picture"> Upload your picture <span class="required">*</span></label>
<input type="file" class="form-control" name="picture" required>
</div>
<div class="col-lg-6">
<label for="sign"> Upload your signature <span class="required">*</span></label>
<input type="file" class="form-control" name="sign" required>
</div>
</div><br>
<div class="row">
<div class="col-md-12">
<input type="checkbox" aria-label="..." name="agree_terms" value="1"> I agree with Rules and Regulations mentioned below.<br>
<input type="checkbox" aria-label="..." name="agree_cond" value="1"> I hearbly declare that Adarsh Classes can use my pictures after my selection for advertising purpose.
</div><!-- /.col-lg-6 -->
</div><!-- /.row -->
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<button type="text" name="submit" class="btn btn-success btn-lg btn-block" name="applyAdmission"> Submit my application form </button>
</div>
</div>
</div>
</form>
The reason behind that in the input type of the HTML Page for the submit you are using <input type="button"
instead of <input type="submit". Use <input type="submit" that's work.
Example:
<input type="submit" name="" value="Submit">
Changed
<button type="text">
to
<button type="submit">
Change
button type="text" to type="button" Or input type ="submit/button"
You need to change this code:
<button type="text" name="submit" class="btn btn-success btn-lg btn-block" name="applyAdmission"> Submit my application form </button>
with below code :
<input type="submit" name="applyAdmission" value="Submit my application form" class="btn btn-success btn-lg btn-block" />
You also need to make sure that your wrote PHP code in same file, otherwise you have to add PHP file name in action tag in below line:
<form class="form-horizontal" id="admission_form" method="post" action="" enctype="multipart/form-data">
You also have some PHP error in your code, so you have to add first line in your PHP code and then fix your PHP Fatal error.
ini_set('display_errors', '1');
I see a little syntax error and I think fixing this will fix your issue.
Change
include ("include/header.php"), include ("include/config.php");
to
include ("include/header.php");
include ("include/config.php");
To show you the syntax error, here is an example:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 'On');
include("test.php"), include("someother.php");
The response:
Parse error: syntax error, unexpected ',' in ...\tests\includeTest.php on line 6
Incorrect input type
You should also change your button type.
Change
<button type="text"...
to
<button type="submit"...
Change <button> to <input>. Buttons can work with javascript but with only php button cant work with post data. You can not get POST data by <button>. For this you have to use <input>
Change this
<button type="text" name="submit" class="btn btn-success btn-lg btn-block" name="applyAdmission"> Submit my application form </button>
to
<input type="submit" name="applyAdmission">
Second:
Here is looking syntax error include ("include/header.php"), include ("include/config.php");
PHP requires instructions to be terminated with a semicolon at the end of each statement. Make them seperate by ; not by ,.
include ("include/header.php");
include ("include/config.php");
You can see documentation for more deep information
In spite of the fact that I'll probably look like a complete idiot, I'm going to post my entire files to see what I'm doing wrong.
I have form built into the page like so:
<form method="post" class="form-horizontal" id="final_form" action="send_mail.php">
<h2>Search for your dream home<br />
and save now!</h2>
<legend>Which Areas are you interested in?</legend>
<div class="areas row-fluid" style="text-align:left !important;">
<div class='span5' style='margin-left:0px !important;'>
<label>
<input type="checkbox" name="arrayValue[]" id="area[0]" value="Sparks" style='margin-top:-5px !important;'> Sparks</label>
</div>
<div class='span5' style='margin-left:0px !important;'>
<label >
<input type="checkbox" name="arrayValue[]" id="area[1]" value="Stead" style='margin-top:-5px !important;'> Stead</label>
</div>
<div class='span5' style='margin-left:0px !important;'>
<label>
<input type="checkbox" name="arrayValue[]" id="area[2]" value="North Reno" style='margin-top:-5px !important;'> North Reno</label>
</div>
<div class='span5' style='margin-left:0px !important;'>
<label >
<input type="checkbox" name="arrayValue[]" id="area[3]" value="South Reno" style='margin-top:-5px !important;'> South Reno</label>
</div>
<div class='span5' style='margin-left:0px !important;'>
<label >
<input type="checkbox" name="arrayValue[]" id="area[4]" value="Double Diamond" style='margin-top:-5px !important;'> Double Diamond</label>
</div>
</div>
<input type="button" onclick="jQuery('#myModal').modal('show')" value="CONTINUE" />
</div>
</div>
</div>
<!--banner area end-->
<!--content area 1 start-->
<div id="content1">
<div class="content1_in"> <span>
<h2 style="line-height:40px;font-size:40px;padding-bottom:10px">Some Content</h2>
<p style="line-height:30px;font-size:22px;text-align: left">Some Content!</p>
</span>
<div class="img">
<img src="image" alt="" />
</div>
</div>
</div>
<!--content area 1 end-->
<!--content area 1 start-->
<div id="content2">
<div class="content2_in"> <span>
</span>
<div class="img">
<img src="http://f14.co/realtor/assets/images/ipad-img.png" alt="" />
<div class="key"></div>
</div>
</div>
</div>
<!--content area 1 end-->
<!--content area 3 start-->
<div id="content3">
<div class="content3_in">
<div class="img">
<img src="image" alt=""
/>
</div>
<div class="free"></div>
</div>
</div>
<!--content area 3 end-->
<div id="footer">
<div class="footer_in">
This Website Is Brought To You By: Ken Holden</div>
</div>
<!-- Modal -->
<div id="myModal" class="modal hide fade modal-survey" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
<h3 id="myModalLabel" class="survey_title">What type of home are you looking for?</h3>
</div>
<input type="hidden" name="template" id="template" value="Buyers" />
<div class="modal-body">
<div id="lead_info_1">
<div class="input select">
<div class=""></div>
<div class="span-4 step-2-dropdown append-bottom control-group">
<select class="span3 required" name="minPrice" id="minPrice">
<option value="">Price</option>
<option value='$50,000 - $150000'>$50,000 - $150000</option><option value='$150,000 -
$300,000'>$150,000 - $300,000</option><option value='$300,000 - $400,000'>
$300,000 - $400,000</option><option value='$400,000 +'>$400,000 +</option>
</select>
</div>
</div>
<div class="input select">
<div class=""></div>
<div class="span-4 step-2-dropdown append-bottom control-group">
<select class="span3 required" name="minBedrooms" id="minBedrooms">
<option value="">Bedrooms</option>
<option value='1-2'>1-2</option><option value='2-4'>2-4</option><option value='4+'>4+
</option> </select>
</div>
</div>
<div class="input select">
<div class=""></div>
<div class="span-4 step-2-dropdown append-bottom control-group">
<select class="span3 required" name="minBathrooms" id="minBathrooms">
<option value="">Bathrooms</option>
<option value='1-2'>1-2</option><option value='2-4'>2-4</option><option value='4+'>4+
</option> </select>
</div>
</div>
<div class="input select">
<div class=""></div>
<div class="span-8 step-2-dropdown2 append-bottom control-group">
<select class="span3 required" name="realtor" id="realtor">
<option value="">Currently Working With a Realtor</option>
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
</div>
</div>
<div class="input select">
<div class=""></div>
<div class="span-8 step-2-dropdown2 append-bottom control-group">
<select class="span3 required" name="move" id="move">
<option value="">When Do You Plan On Moving?</option>
<option value="30-90 days">30-90 days</option>
<option value="90-120 days">90-120 days</option>
<option value="I'm just looking">I'm just looking</option>
</select>
</div>
</div>
<!--<img src="http://localcommissionsystem.com/assets/app/images/SearchDealsLikeThis.png" />-->
</div>
<div id="lead_info_2" style="display:none">
<center>
</center>
</div>
<div id="lead_info_3" style="display:none">
<textarea class="" id="wantedArea" name="wantedArea" style="display:none;"></textarea>
<div class="control-group">
<label class="control-label" for="fname">First Name</label>
<div class="controls">
<input class="required" type="text" id="fname" name="fname" placeholder="First Name" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="email">Email</label>
<div class="controls">
<input class="required" type="text" id="email" name="email" placeholder="Valid Email Required" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="phone">Cell Phone</label>
<div class="controls">
<input class="required" type="text" id="phone" name="phone" placeholder="Cell Phone" />
</div>
</div>
</div>
</div>
Here is the php
<?php
$webmaster_email = "email#email.com";
$webmaster_email2 = "email#email.com";
$fname = $_REQUEST['fname'];
$email = $_REQUEST['email'];
$phone = $_REQUEST['phone'];
$minBedrooms = $_REQUEST['minBedrooms'];
$minBathrooms = $_REQUEST['minBathrooms'];
$minPrice = $_REQUEST['minPrice'];
$move = $_REQUEST['move'];
$realtor = $_REQUEST['realtor'];
if( !empty($_REQUEST) && is_array($arrayValue) ) {
$arrayValue = array();
$areas = implode("," , $_REQUEST['arrayValue']);
}
$emailfrom = $_REQUEST['email'];
$headers = 'From: '.$emailfrom."\r\n".
$email_to = "test#gmail.com, ";
/* This bit sets the URLs of the supporting pages.
If you change the names of any of the pages, you will need to change the values here.
*/
$feedback_page = "index.html";
$thankyou_page = "thankyou.html";
/*
The following function checks for email injection.
Specifically, it checks for carriage returns - typically used by spammers to inject a CC
list.
*/
function isInjected($str) {
$injections = array('(\n+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str)) {
return true;
}
else {
return false;
}
}
// If the user tries to access this script directly, redirect them to the feedback
form,
if (!isset($_REQUEST['email'])) {
header( "Location: $feedback_page" );
}
// If email injection is detected, redirect to the error page.
elseif ( isInjected($email) ) {
header( "Location: $error_page" );
}
// If we passed all previous tests, send the email then redirect to the thank you page.
else {
mail( $email_to, "You Have a New Lead",
"Name: $fname\nEmail: $email\nPhone: $phone\nMinBedrooms: $minBedrooms\nMinPrice:
$minPrice\nMove Date: $move\nRealtor: $realtor\nAreas: $areas", $headers );
}
echo "<script>window.location = 'thankyou.html'</script>";
?>
My checkboxes are not returning any values. Does anyone know why? I've worked to make things correct and I think I've got the array set up right thanks to the help of another question, but I think I'm asking the wrong question in my other post.
Your $arrayValue is not defined before the first if statement which is why the is_array($arrayValue) does not succeed. Please try:
if( !empty($_REQUEST['arrayValue'])) {
$arrayValue = array();
$areas = implode("," , $_REQUEST['arrayValue']);
}
In your HTML this should be the name:
<input type="checkbox" name="arrayValue" id="area[4]" value="Double Diamond" style='margin-top:-5px !important;'> Double Diamond</label>
In your PHP
if( !empty($_REQUEST) && is_array($arrayValue) )
{
$arrayValue = array();
$arrayValue[] = $_REQUEST['arrayValue'];
}
$areas = implode(",",$arrayValue);
put it in the array first then implode it as a string.
just check by printing php global variable $_REQUEST on your php. You can do it by writing print_r($_REQUEST); if it does not shows anything or black array, make use of $_POST instead of $_REQUEST at each place in php file. Hope it will solve your problem.