Problem taking different values from form - php

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>

Related

how to Get selected option value within PHP page reload

<div class="form-group row">
<label for="event_name" class="col-sm-2 col-md-1 col-form-label">Event Name</label>
<div class="col-sm-4 col-md-4">
<select class="form-control event" name='event_name' id='event_name'>
<option value="Option_1">Option 1</option>
<option value="Option_2">Option 2</option>
<option value="Option_3">Option 3</option>
<option value="Option_4">Option 4</option>
<option value="Option_5">Option 5</option>
</select>
</div>
</div>
<h4>{Event name}</h4>
my question is how to get {Event name} when i select any option?
You can do with easily with a session within a form. Just do something at the top like:
<?php
if (isset($_GET['form'])) {
$_SESSION['eName'] = $_GET['event_name'];
}
?>
<div class="form-group row">
<label for="event_name" class="col-sm-2 col-md-1 col-form-label">Event Name</label>
<div class="col-sm-4 col-md-4">
<form method="GET" action="">
<select class="form-control event" name='event_name' id='event_name'>
<option value="Option_1">Option 1</option>
<option value="Option_2">Option 2</option>
<option value="Option_3">Option 3</option>
<option value="Option_4">Option 4</option>
<option value="Option_5">Option 5</option>
</select>
<input type="submit" name="form">
</form>
</div>
</div>
<h4><?php if(isset($_SESSION['eName'])) { echo $_SESSION['eName']; }?></h4>
i got my answer and it's for without submitting value
<?PHP
$event_name = $_GET['event_name'];
?>
<script>
jQuery(function($){
$('#event_name').change(function(e){
let event_name = e.target.value;
window.location.href = `/wp-admin/admin.php?pageName&event_name=${event_name}`;
});
}
</script>

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

Where does this form redirect?

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>

3 dependent multi dropdown list same select name how to insert into mysql using php?

3 dependent multi dropdown list same select name at the end of the select field each drop down. When i click portfolio level option based on the div display show one dependent dropdown list among three. When i click at showed dropdown list only posted to last selected value. In that i make every drop down list last select name same; i.e name=worklocation.
The html code below:
<form method="post" action="user-work.php" enctype="multipart/form-data">
<div class="form-group">
<select name="pfLevel" id="portfolio_levels" class="form-control">
<option value="">Select Portfolio Level</option>
</select>
</div>
<div style='display:none;' id='Countryshow' class="form-group">
<select name="workLocation[]" id="counrey7" class="form-control">
<option value="">Select Country</option>
</select>
</div>
<div style='display:none;' id='stateshow'>
<div class="form-group">
<select name="" id="country6" class="form-control">
<option value="">Select country</option>
</select>
</div>
<div class="form-group">
<select name="workLocation[]" id="state6" class="form-control">
<option value="">Select State</option>
</select>
</div>
</div>
<div style='display:none;' id='cityshow'>
<div class="form-group">
<select name="" id="country5" class="form-control">
<option value="">Select country</option>
</select>
</div>
<div class="form-group">
<select name="" id="state5" class="form-control">
<option value="">Select state</option>
</select>
</div>
<div class="form-group">
<select name="workLocation[]" id="city5" class="form-control">
<option value="">Select city</option>
</select>
</div>
</div>
<div class="col-xs-12"><div class="btn-group text-left">
<button class="btn btn-primary">Submit</button>
<button class="btn btn-secondry">Close</button>
</div></div>
</form>
php code
<?php
require 'inc/database.php';
if ( !empty($_POST)) {
$pfLevel=$_POST['pfLevel'];
$workLocation=$_POST['workLocation'];
$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "INSERT INTO userworkinfo (intWorkLocation,userPfLevel) values(?,?)";
$q = $pdo->prepare($sql);
$q->execute(array($workLocation,$pfLevel));
Database::disconnect();
echo '<script>alert("working details posted successfully");</script>';
}
?>
Use select input name with index.
<select name="workLocation[0]" id="counrey7" class="form-control">
<option value="">Select Country</option>
</select>
<select name="workLocation[1]" id="state6" class="form-control">
<option value="">Select state</option>
</select>
<select name="workLocation[2]" id="city5" class="form-control">
<option value="">Select city</option>
</select>

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'

Categories