Where does this form redirect? - php

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>

Related

Calling POST data from a PHP file

I have 3 php files and I want to get the month from form1.php for form3.php but the thing is, it needs to be processed in form2.php as well, how can I just get the month from form1 and display it in form3?
form1.php
<form action="form2.php" method="post">
<div class="form-title">
<p class="display-6">Salary Calculator (Part 1)</p>
</div>
<div class="form-subtitle">
<p>Employee Information</p>
</div>
<div class="form-row">
<div class="form-row-child">
<label for="inputPlaceholder4">Employee Name</label>
<select class="form-select" aria-label="Default select example" name="displayName" id="displayName">
<option selected>Select Employee</option>
<?php while($row = $result->fetch_assoc()) { ?>
<option value="<?php echo $row['displayName']; ?>"><?= $row["displayName"] ?></option>
<?php }; ?>
</select>
</div>
<div class="form-row-child">
<label for="inputPlaceholder4">Month</label>
<select class="form-select" aria-label="Default select example" name="month" id="month">
<option selected disabled>Select Month</option>
<option value="January">January</option>
<option value="Febuary">Febuary</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-row">
<div class="form-row-child">
<input type="submit" class="btn btn-danger form1-btn" value="Proceed">
</div>
<div class="form-row-child">
</div>
</div>
</form>
form2.php
<form action="form3.php" method="post">
<div class="form-title">
<p class="display-6">Salary Calculator (Part 2)</p>
</div>
<div class="half-form">
<div class="half-form-left">
<div class="half-form-subtitle">
<p>Holidays</p>
</div>
<div class="half-form-child">
<label for="inputPlaceholder3">Regular (Per day)</label>
<select class="form-select" aria-label="Default select example" name="holidayReg" id="holidayReg">
<?php foreach ($regHolidays as $value) { ?>
<option value="<?php echo $value; ?>"><?= $value ?></option>
<?php }; ?>
</select>
</div>
<div class="half-form-child">
<label for="inputPlaceholder3">Special (Per day)</label>
<select class="form-select" aria-label="Default select example" name="holidaySpec" id="holidaySpec">
<?php foreach ($specHolidays as $value) { ?>
<option value="<?php echo $value; ?>"><?= $value ?></option>
<?php }; ?>
</select>
</div>
</div>
<div class="half-form-right">
<div class="half-form-subtitle">
<p>Overtime</p>
</div>
<div class="half-form-child">
<label for="inputPlaceholder3">Normal (Per hour)</label>
<input type="Placeholder" class="form-control" id="overtimeHoursNormal" placeholder="Placeholder" name="overtimeHoursNormal">
</div>
<div class="half-form-child">
<label for="inputPlaceholder3">Rest Day (Per hour)</label>
<input type="Placeholder" class="form-control" id="overtimeHoursSpecial" placeholder="Placeholder" name="overtimeHoursSpecial">
</div>
</div>
</div>
<div class="half-form">
<div class="half-form-left">
<div class="half-form-subtitle">
<p>Absences</p>
</div>
<div class="half-form-child">
<label for="inputPlaceholder3">Day/s absent</label>
<input type="Placeholder" class="form-control" id="absences" placeholder="Placeholder" name="absences">
</div>
</div>
<div class="half-form-right">
<input type="Placeholder" class="form-control" id="basePay" name="basePay" style="display: none;" value="<?php echo $vagueEmployee->getBasePay(); ?>">
<input type="Placeholder" class="form-control" id="workingHours" name="workingHours" style="display: none;" value="<?php echo $vagueEmployee->getWorkingHours(); ?>">
<input type="Placeholder" class="form-control" id="salaryPerHour" name="salaryPerHour" style="display: none;" value="<?php echo $salaryPerHour; ?>">
<input type="Placeholder" class="form-control" id="payFor13thMonth" name="payFor13thMonth" style="display: none;" value="<?php echo $payFor13thMonth; ?>">
</div>
</div>
<div class="form-row">
<div class="form-row-child">
<input type="submit" class="btn btn-danger form1-btn" value="Proceed">
</div>
<div class="form-row-child">
</div>
</div>
</form>
form3.php
<main class="main">
<div class="form-title">
<p class="display-6">Employee Salary</p>
</div>
<div class="">
<p>Pay after additions: Php <?php echo $payAfterAdditions; ?></p>
<p>Deductions</p>
<p>Philhealth: Php <?php echo $philhealth; ?></p>
<p>SSS: Php <?php echo $sss; ?></p>
<p>Total deductions: Php <?php echo $totalDeductions; ?></p>
<p>Taxable Salary: Php <?php echo $taxableSalary; ?></p>
<p>Final Salary: Php <?php echo $finalTax; ?></p>
<!-- lalabas lang kapag december -->
<p>13 month pay: </p>
<p> <?php echo $totalAbsences; ?></p>
<p> <?php echo $basePay; ?></p>
</div>
</main>
In form 2
Add the following field inside the form
<input type=hidden name=month value="<?php echo $_POST["month"]; ?>">
Then in form 3, you can use $_POST["month"] to access the month value.

Why isn't $conditions being populated in my PHP code and why can't I pull form data?

everyone! I am making a form consisting of fully drop down selectable menus where the user will populate the field. After pressing the submit form, I plan that information will be pulled from a database to display search results to the user. I am a little new to SQL and PHP, so any help would be appreciated! I attached the form and PHP code separately.
<form autocomplete="on" class="form-horizontal" action="" enctype="multipart/form-data" method="POST" name= "unit_assignments">
<div class="col-sm-4">
<h4></h4>
<div class="panel panel-default background-light padded">
<div class="form-group">
<label for="course_designation" class="col-lg-4 control-label">Course</label>
<div class="col-lg-8">
<select type="hidden" class="form-control" name="course_designation" id="course_designation">
<option value="" selected disabled>Please Select</option>
<option value="_105">105</option>
<option value="_105i">105i</option>
</select>
</div>
</div>
</div>
</div>
<div class="col-sm-4">
<h4></h4>
<div class="panel panel-default background-light padded">
<div class="form-group">
<label for="year" class="col-lg-4 control-label">Year</label>
<div class="col-lg-8">
<select type="hidden" class="form-control" name="year" id="year">
<option value="" selected disabled>Please Select</option>
<option value="_2018">2018</option>
<option value="_2017">2017</option>
<option value="_2016">2016</option>
<option value="_2015">2015</option>
<option value="_2014">2014</option>
<option value="_2013">2013</option>
<option value="_2012">2012</option>
<option value="_2011">2011</option>
</select>
</div>
</div>
</div>
</div>
<div class="col-sm-4">
<h4></h4>
<div class="panel panel-default background-light padded">
<div class="form-group">
<label for="semester" class="col-lg-4 control-label">Semester</label>
<div class="col-lg-8">
<select type="hidden" class="form-control" name="semester" id="semester">
<option value="" selected disabled>Please Select</option>
<option value="fall">Fall</option>
<option value="spring">Spring</option>
<option value="summer">Summer</option>
<option value="maymester">Maymester</option>
</select>
</div>
</div>
</div>
</div>
<div class="col-sm-4">
<h4></h4>
<div class="panel panel-default background-light padded">
<div class="form-group">
<label for="discipline" class="col-lg-4 control-label">Discipline</label>
<div class="col-lg-8">
<select type="hidden" class="form-control" name="discipline" id="discipline">
<option value="" selected disabled>Please Select</option>
<option value="nat_sciences">Natural Sciences</option>
<option value="health_medicine">Health Medicine</option>
<option value="social_sciences">Social Sciences</option>
<option value="humanities">Humanities</option>
<option value="digital_humanities">Digital Humanities</option>
<option value="law">Law</option>
<option value="business">Business</option>
</select>
</div>
</div>
</div>
</div>
<div class="col-sm-4">
<h4></h4>
<div class="panel panel-default background-light padded">
<div class="form-group">
<label for="digital_literacy" class="col-lg-4 control-label">Type</label>
<div class="col-lg-8">
<select type="hidden" class="form-control" name="digital_literacy" id="digital_literacy">
<option value="" selected disabled>Please Select</option>
<option value="podcast">Podcast</option>
<option value="video">Video</option>
<option value="webpage">Webpage</option>
<option value="sparks">Sparks</option>
<option value="illustrator">Illustrator</option>
<option value="in_design">In Design</option>
<option value="canvas">Canvas</option>
<option value="pitochart">Pitochart</option>
<option value="power_point">Power Point</option>
<option value="spreadsheet">Spreadsheet</option>
</select>
</div>
</div>
</div>
</div>
<div class="col-sm-4">
<h4></h4>
<div class="panel panel-default background-light padded">
<div class="form-group">
<label for="genre" class="col-lg-4 control-label">Genre</label>
<div class="col-lg-8">
<select type="hidden" class="form-control" name="genre" id="genre">
<option value="" selected disabled>Please Select</option>
<option value="book_review">Book Review</option>
<option value="film_review">Film Review</option>
<option value="play_review">Play Review</option>
<option value="literature_review">Literature Review</option>
<option value="peer_reviewed_journal_articles">Peer Reviewed Journal Article</option>
<option value="conference_paper">Conference Paper</option>
<option value="conference_presentation">Conference Presentation</option>
<option value="grant_proposal">Grant Proposal</option>
</select>
</div>
</div>
</div>
</div>
<div class="col-sm-4">
<h4></h4>
<div class="panel panel-default background-light padded">
<div class="form-group">
<label for="method" class="col-lg-4 control-label">Method</label>
<div class="col-lg-8">
<select type="hidden" class="form-control" name="method" id="method">
<option value="" selected disabled>Please Select</option>
<option value="archival_research">Archival Research</option>
<option value="textual_analysis">Textual Analysis</option>
<option value="rhetorical_analysis">Rhetorical Analysis</option>
<option value="reviewing_the_literature">Reviewing the Literature</option>
</select>
</div>
</div>
</div>
</div>
<center>
<div class="col-sm-4">
<h4></h4>
<div class="panel panel-default background-light padded">
<center>
<input class="btn btn-primary btn-block" type="submit" value="submit">
</center>
</div>
</div>
</center>
</form>
This is the PHP portion of the code. The page just keeps returning an empty number for conditions and only prints out "SELECT * FROM unit_assignments". It never ends up executing the rest of the code and I was wondering if it was because my PHP code is wrong or my form code. My page does connect to the database, so I don't think there are any database errors.I have tried varying methods of writing the PHP code but to no avail, which leaves me to believe maybe the PHP code and the form just aren't connecting.
<?php
// define the list of fields
$fields = array('course_designation', 'year', 'discipline', 'digital_literacy', 'genre', 'method');
$conditions = array();
// loop through the defined fields
foreach($fields as $field){
// if the field is set and not empty
if(!empty($_POST[$field])) {
// create a new condition while escaping the value inputed by the user (SQL Injection)
$conditions[] = "`$field` LIKE '%" . mysqli_real_escape_string($_POST[$field]) . "%'";
}
}
// }
// builds the query
$query = "SELECT * FROM unit_assignments ";
echo count($conditions);
// if there are conditions defined
if(count($conditions) > 0) {
// append the conditions
$query .= "WHERE " . implode (' AND ', $conditions); // you can change to 'OR', but I suggest to apply the filters cumulative
}
echo "$query";
$result = mysqli_query($mysqli_link, $query);
mysqli_close($mysqli_link);
if(isset($_POST['submit'])) {
while($row = mysqli_fetch_array($result)) {
$course_designation = $row['course_designation'];
$year = $row['year'];
$discipline = $row['discipline'];
$digital_literacy = $row['digital_literacy'];
$genre = $row['genre'];
$method = $row['method'];
echo "Course: $course_designation<br>Year: $year<br>Discipline: $discipline<br>digital_literacy: $digital_literacy<br>Genre: $genre<br>Method: $method<br>";
}
}
?>

PHP upload two files on server, info in mySQL db

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); }
?>

When I choose 'any' option from select type and click submit, I want to display all the data from MySQL database

I want to display all the data from table in MySQL database when I choose 'any' option. I don't know how to do that. Please look at the code below.
<form method="post" action="listing_grid.php">
<div class="row">
<div class="col-lg-4 col-md-4 col-sm-6">
<div class="formBlock select">
<label for="location">Property for: </label><br/>
<select name="property_for" id="beds" class="formDropdown">
<option value="Property for sale">Property for sale</option>
<option value="Property for rent">Property for rent</option>
</select>
</div>
</div>
<div class="col-lg-4 col-md-4 col-sm-6">
<div class="formBlock select">
<label for="propertyType">Property Type</label><br/>
<select name="property_type" id="propertyType" class="formDropdown">
<option value="any">Any</option>
<option value="Houses">Houses</option>
<option value="Apartments">Apartments</option>
<option value="Bungalows">Bungalows</option>
<option value="Land">Land</option>
<option value="Commercial property">Commercial property</option>
</select>
</div>
</div>
<div class="col-lg-4 col-md-4 col-sm-6">
<div class="formBlock">
<label for="price-min">Price Range</label><br/>
<div style="float:right; margin-top:-25px;">
<div class="priceInput"><input type="text" name="price_min" id="price-min" class="priceInput" /></div>
<span style="float:left; margin-right:10px; margin-left:10px;">-</span>
<div class="priceInput"><input type="text" name="price_max" id="price-max" class="priceInput" /></div>
</div><br/>
<div class="priceSlider"></div>
<div class="priceSliderLabel"><span>0</span><span style="float:right;">800,000</span></div>
</div>
</div>
<div class="col-lg-4 col-md-4 col-sm-6">
<div class="formBlock select">
<label for="location">Location</label><br/>
<input id="tags" type="text" name="location">
</div>
</div>
<div class="col-lg-3 col-md-3 col-sm-6">
<div class="formBlock select">
<label for="beds">Beds</label><br/>
<select name="beds" id="beds" class="formDropdown">
<option value="any">Any</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-lg-3 col-md-3 col-sm-6">
<div class="formBlock select">
<label for="baths">Baths</label><br/>
<select name="baths" id="baths" class="formDropdown">
<option value="any">Any</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-lg-3 col-md-3 col-sm-6">
<div class="formBlock select">
<label for="area2">Search radius</label><br/>
<select name="area" id="area2" class="formDropdown">
<option value="any">Any</option>
<option value="0.25">within 1/4 mile</option>
<option value="0.5">within 1/2 mile</option>
<option value="1">within 1 mile</option>
<option value="3">within 3 miles</option>
<option value="5">within 5 miles</option>
<option value="10">within 10 miles</option>
<option value="20">within 20 miles</option>
<option value="30">within 30 miles</option>
<option value="40">within 40 miles</option>
</select>
</div>
</div>
<div class="col-lg-4 col-md-4 col-sm-6">
<div class="formBlock">
<label for="price-min">Size Range (Square Feet)</label><br/>
<div style="float:right; margin-top:-25px;">
<div class="priceInput"><input type="text" name="size_min" id="price-min1" class="priceInput" /></div>
<span style="float:left; margin-right:10px; margin-left:10px;">-</span>
<div class="priceInput"><input type="text" name="size_max" id="price-max1" class="priceInput" /></div>
</div><br/>
<div class="priceSlider1"></div>
<div class="priceSliderLabel"><span>0</span><span style="float:right;">80,000</span></div>
</div>
</div>
<div class="col-lg-3 col-md-3 col-sm-6">
<div class="formBlock">
<input class="buttonColor" type="submit" name="find_property" value="FIND PROPERTIES" style="margin-top:24px;">
</div>
</div>
<div style="clear:both;"></div>
</div>
</form>
Here when i choose 'any' option, I want to display all the data from my table...
I am using query like below
$property_for=$_POST['property_for'];
$property_type=$_POST['property_type'];
$price_min=$_POST['price_min'];
$price_max=$_POST['price_max'];
$location=$_POST['location'];
$beds=$_POST['beds'];
$baths=$_POST['baths'];
$area=$_POST['area'];
$size_min=$_POST['size_min'];
$size_max = $_POST['size_max'];
$property_listing_for_sale = "";
$sql = mysqli_query($con, "SELECT * FROM properties WHERE category = '$property_for' AND bed_rooms = '$beds' AND bath_rooms = '$baths' ORDER BY date_added DESC") or die(mysqli_error($con));
I am newbie.. so help me.. Thanks in advance..
You should work with dynamic query's:
$baths = $_POST['baths'];
if ($baths == '*') {
$query = "select * from properties ";
} else {
$query = "select * from properties where baths = '$baths'"
}
Also you should learn about prepared statements.
A second way is to change your option value to %
<option value="Any">
And then you can use the following query:
select * from properties where baths like '$baths'

PHP email from submit and stay on page

Below is the code I'm using for my form. At the moment, when the form is submitted the message is shown on a separate page. I just want a message above the current form as appose to on a new page.
<div class="main_box">
<div class="clear"></div>
<div class="clear"></div>
<?php
$action=$_REQUEST['action'];
if ($action=="") /* display the contact form */
{
?>
<form action="" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="submit">
<div class="main_col">
<div class="main_col_left"><strong>BUSINESS NAME:</strong></div>
<div class="main_col_right">
<input type="text" name="business" id="business" value="" />
</div>
</div>
<div class="main_col">
<div class="main_col_left"><strong>EMAIL ADDRESS:</strong></div>
<div class="main_col_right">
<input type="text" name="email" id="email" value="" />
</div>
</div>
<div class="main_col">
<div class="main_col_left"><strong>PROPERTY PURCHASE PRICE:</strong><span><strong>£</strong></span></div>
<div class="main_col_right">
<input type="text" name="pur_price" id="pur_price" value="" />
</div>
</div>
<div class="main_col">
<div class="main_col_left"><strong>REFURB COST:</strong><span><strong>£</strong></span></div>
<div class="main_col_right">
<input type="text" name="refurb" id="refurb" value="" />
</div>
</div>
<div class="main_col">
<div class="main_col_left"><strong>Property Type :</strong></div>
<div class="main_col_right">
<select name="select2" id="select2" onchange="propType(this.value);">
<option value="">Select Property Type</option>
<option value="0.3">Car Showroom</option>
<option value="0.4">Care/Nursing Home</option>
<option value="0.25">Dental Surgery</option>
<option value="0.3">Department Store</option>
<option value="0.3">Distribution Centre</option>
<option value="0.3">FHL Apartment</option>
<option value="0.3">FHL House</option>
<option value="0.3">FHL Villa</option>
<option value="0.3">Hotel/B&B </option>
<option value="0.25">Industrial</option>
<option value="0.3">Industrial with Office</option>
<option value="0.3">Medical Centre</option>
<option value="0.25">Multi-Storey Car Park</option>
<option value="0.35">Nursery</option>
<option value="0.25">Office</option>
<option value="0.25">Office with Residential</option>
<option value="0.3">Petrol Station</option>
<option value="0.3">Public House</option>
<option value="0.3">Research Facility</option>
<option value="0.3">Restaurant</option>
<option value="0.25">Retail Warehouse</option>
<option value="0.3">Retail Shop</option>
<option value="0.3">Retail Shop & Office</option>
<option value="0.3">Shopping Centre</option>
<option value="0.3">Sports Centres</option>
<option value="0.3">Students Residence</option>
<option value="0.3">Theatre</option>
<option value="0.3">OTHER</option>
</select>
</div>
</div>
<div class="main_col" style="display:none">
<div class="main_col_left"><strong>AVERAGE CLAIM RATE :</strong><span><strong>£</strong></span></div>
<div class="main_col_right">
<input type="text" name="avg_claim_rate" id="avg_claim_rate" value="" />
</div>
</div>
<div class="main_col">
<div class="main_col_left"><strong>AMOUNT CLAIMABLE :</strong><span><strong>£</strong></span></div>
<div class="main_col_right">
<input type="text" name="amount_claim" id="amount_claim" value="" />
</div>
</div>
<div class="main_col">
<div class="main_col_left"><strong> YOUR TAX RATE :</strong></div>
<div class="main_col_right">
<select name="tax_rate" id="tax_rate">
<option value=".24">24%</option>
<option value=".4">40%</option>
</select>
</div>
</div>
<div class="clear"></div>
<hr />
<div class="clear"></div>
<div class="main_col">
<div class="main_col_left"><strong>CLIENT TAX BENEFIT :</strong><span><strong>£</strong></span></div>
<div class="main_col_right"><input type="text" name="client_benefit" id="client_benefit" value="" /></div>
</div>
<div class="main_col">
<div class="main_col_left"><strong>INSTANT CASH RECLAIM:</strong><span><strong>£</strong></span></div>
<div class="main_col_right"><input type="text" name="cash_reclaim" id="cash_reclaim" value="" /></div>
</div>
<div class="main_col">
<div class="main_col_left"><strong>FUTURE TAX RELIEF :</strong><span><strong>£</strong></span></div>
<div class="main_col_right"><!--<span id="future_tax_rel"></span>--> <input type="text" name="future_tax_rel" id="future_tax_rel" value="" /></div>
</div>
<div class="clear"></div>
<hr />
<div class="clear"></div>
<p style="line-height:20px;">Note : These figures are estimates and the final figures may very depending upon the property and full circusstances</p>
<div class="clear"></div>
<div class="clear"></div>
<div class="main_col">
<div class="main_col_left"> </div>
<div class="main_col_right">
<button onclick="calculate();">Calculate</button>
</div>
</div>
</form>
<?php
}
else /* send the submitted data */
{
$name=$_REQUEST['business'];
$email=$_REQUEST['email'];
$pur_price=$_REQUEST['pur_price'];
$refurb=$_REQUEST['refurb'];
$select2=$_REQUEST['select2'];
$select=$_REQUEST['select'];
if (($name=="")||($email==""))
{
echo "Please enter business name & email";
}
else{
$from="Business : $name\r\nEmail : $email\r\nPurchase Price : $pur_price\r\nRefurb Cost : $refurb";
$subject="CTA Associates Calculator ";
mail("test#test.com", $subject, $from);
}
}
?>
<button onclick="reset();">Reset</button>
<div class="clear"></div>
<div class="clear"></div>
</div>
you can use something like this
<?php
if(isset($_GET['status']))
echo "success";
?>
end in the end of your code add header('Location:page.php?status')

Categories