PHP Validating Form - php

I am having trouble showing the output that i called in printf in php tutorial. I just followed the tutorial but still can't figure out what is wrong in displaying the variables inside the printf in localhost. Is anyone can help me. Thank you.
<?php
$name = '';
$password = '';
$gender = '';
$color = '';
$languages = [];
$comments = '';
$tc = '';
if (isset($_POST['submit'])) {
if (isset($_POST['name'])) {
$name = $_POST['name'];
};
if (isset($_POST['password'])) {
$password = $_POST['password'];
};
if (isset($_POST['gender'])) {
$gender = $_POST['gender'];
};
if (isset($_POST['color'])) {
$color = $_POST['color'];
};
if (isset($_POST['languages'])) {
$languages = $_POST['languages'];
};
if (isset($_POST['comments'])) {
$comments = $_POST['comments'];
};
if (isset($_POST['tc'])) {
$tc = $_POST['tc'];
};
//here's the problem i cant resolve printing out the output//
printf('User name: %s
<br>Password: %s
<br>Gender: %s
<br>Color: %s
<br>Language(s): %s
<br>Comments: %s
<br>T&C: %s',
htmlspecialchars($name, ENT_QUOTES),
htmlspecialchars($password, ENT_QUOTES),
htmlspecialchars($gender, ENT_QUOTES),
htmlspecialchars($color, ENT_QUOTES),
htmlspecialchars(implode('', $languages), ENT_QUOTES),
htmlspecialchars($comments, ENT_QUOTES),
htmlspecialchars($tc, ENT_QUOTES));
}
?>
<form action=""
method="post">
User name: <input type="text" name="name"><br>
Password: <input type="password" value="password"><br>
Gender:
<input type="radio" name="gender" value="f"> female
<input type="radio" name="gender" value="m"> male
<input type="radio" name="gender" value="o"> other<br/>
Favorite color:
<select name="color">
<option value="">Please select</option>
<option value="#f00">red</option>
<option value="#0f0">green</option>
<option value="#00f">blue</option>
</select><br>
Languages spoken:
<select name="languages[]"multiple size="3">
<option value="en">English</option>
<option value="fr">French</option>
<option value="it">Italian</option>
</select><br>
Comments: <textarea name="comments"></textarea><br>
<input type="checkbox" name="tc" value="ok"> I accept the T&C<br>
<input type="submit" value="Register">
</form>`

The problem here is if (isset($_POST['submit'])) there is no any form field with the name submit and it will never become true to execute. Remove the if Condition with submit or Else give the sumbit button name as Submit
<input type="submit" value="Register" name="submit">

Errors in your previous code are:
No semicolons ; are needed after ending if statements.
No name attribute is specified for password input in the form.
Posting form data as if (isset($_POST['submit'])) {...} without specifying the name="submit" attribute in the form.
Invalid use of implode function which will generate output be like enfrit or vice versa.
Additional Tips
Add the required attribute to each input to prevent from sending empty form data.
You have already specified method="post" in the form tag so, no need for validating each input field as if (isset($_POST['fieldname'])) {...} . if (isset($_POST['submit'])) {...} will send all the form data as POST method.
And lastly, here is your updated code.
<?php
if (isset($_POST['submit'])) {
$name = '';
$password = '';
$gender = '';
$color = '';
$languages = [];
$comments = '';
$tc = '';
if (isset($_POST['name'])) {
$name = $_POST['name'];
}
if (isset($_POST['password'])) {
$password = $_POST['password'];
}
if (isset($_POST['gender'])) {
$gender = $_POST['gender'];
}
if (isset($_POST['color'])) {
$color = $_POST['color'];
}
if (isset($_POST['languages'])) {
$languages = $_POST['languages'];
}
if (isset($_POST['comments'])) {
$comments = $_POST['comments'];
}
if (isset($_POST['tc'])) {
$tc = $_POST['tc'];
}
//print output
printf('User name: %s
<br>Password: %s
<br>Gender: %s
<br>Color: %s
<br>Language(s): %s
<br>Comments: %s
<br>T & C: %s
<br><br>',
htmlspecialchars($name, ENT_QUOTES),
htmlspecialchars($password, ENT_QUOTES),
htmlspecialchars($gender, ENT_QUOTES),
htmlspecialchars($color, ENT_QUOTES),
htmlspecialchars(implode(', ', $languages), ENT_QUOTES),
htmlspecialchars($comments, ENT_QUOTES),
htmlspecialchars($tc, ENT_QUOTES));
}
?>
<form action="" method="post">
User name: <input type="text" name="name">
<br>
Password: <input type="password" name="password">
<br>
Gender:
<input type="radio" name="gender" value="f"> female
<input type="radio" name="gender" value="m"> male
<input type="radio" name="gender" value="o"> other
<br>
Favorite color:
<select name="color">
<option value="">Please select</option>
<option value="#f00">red</option>
<option value="#0f0">green</option>
<option value="#00f">blue</option>
</select>
<br>
Languages spoken:
<select name="languages[]" multiple size="3">
<option value="en">English</option>
<option value="fr">French</option>
<option value="it">Italian</option>
</select>
<br>
Comments: <textarea name="comments"></textarea>
<br>
<input type="checkbox" name="tc" value="ok"> I accept the T & C
<br>
<input type="submit" name="submit" value="Register">
</form>

Related

Convert String from PHP to int in SQL

I have the following basic HTML form:
<form action="" method="post">
Name: <input type="text" name="name" /><br><br>
College: <select name = "colleges">
<option> ---Select College---</option>
<option value="option1">DIT</option>
<option value="option2">University College Dublin</option>
</select><br><br>
Email: <input type="text" name="email" /><br><br>
Password: <input type="text" name="password" /><br><br>
Location: <input type="text" name="location" /><br><br>
<button type="submit" name="submit" >Submit</button>
</form>
And the following section of PHP which I am quite new to:
if(isset($_POST["submit"])) {
$name = $_POST["name"];
$college_name = $_POST["college"];
$email = $_POST["email"];
$password = $_POST["password"];
$location = $_POST["location"];
}
$sql = "INSERT INTO user(name, college, email, password, location) VALUES ($name, $college_name, $email, $password, $location)";
?>
My database has college as an int, so DIT would be 1 in the database. Can anyone tell me how to do this so that it sends 1 as college_name instead of the actual name that the user sees?
Change this
College: <select name = "colleges">
<option> ---Select College---</option>
<option value="option1">DIT</option>
<option value="option2">University College Dublin</option>
</select><br><br>
to this
College: <select name = "colleges">
<option> ---Select College---</option>
<option value="1">DIT</option>
<option value="2">University College Dublin</option>
</select><br><br>
and this
if(isset($_POST["submit"])) {
$name = $_POST["name"];
$college_name = $_POST["college"];
$email = $_POST["email"];
$password = $_POST["password"];
$location = $_POST["location"];
}
to this
if(isset($_POST["submit"])) {
$name = $_POST["name"];
$college_name = (int) $_POST["colleges"];
$email = $_POST["email"];
$password = $_POST["password"];
$location = $_POST["location"];
}
In your options put numerical values:
College: <select name="colleges">
<option value="1">DIT</option>
<option value="2">University College Dublin</option>
</select>
then correct your php to match the name of the select in the $_POST array:
$college_name = (int) $_POST["colleges"];
Just use
<option value='1' > DIT </option>
Instead of adding option1 as a value
Why arent you using the option value?
$_POST["college"] is returning option1
I think the correct way is defining the value as 1:
The following:
<option value="1">DIT</option>
Will return: 1
You can also use a If else statement
if ($_POST["college"] == 'option1')
{
$college = 1;
}
if ($_POST["college"] == 'option2')
{
$college = 2;
}

passing html variable to multiple php files

I am building a family tree for a class assignment and I have to pass variables from an HTML form to a PHP file for that family member depending on whose information is being updated. I need the form variables to be able to pass to the php file for father, mother, wife, ect.
HTML File
<form action="handle_family.php" method="post">
<p>Family Member: <select name="name">
<option value="david">David</option>
<option value="linda">Linda</option>
<option value="cayla">Cayla</option>
<option value="sophie">Sophie</option>
<option value="sawyer">Sawyer</option>
</select></p>
<p>Relationship: <select name="relationship">
<option value="father">Father</option>
<option value="mother">Mother</option>
<option value="wife">Wife</option>
<option value="son">Son</option>
<option value="daughter">Daughter</option>
</select></p>
<p>Interests: <input type="text" name="interests" size="60" /></p>
<p>History: <input type="text" name="history" size="60" /></p>
<p>Occupation: <input type="text" name="occupation" size="60" /></p>
<input type="submit" name="submit" value="Update Page" />
</form>
</div>
handle_family.php
<?php // Script 6.2 - handle_reg.php
ini_set ('display_errors', 1);
error_reporting (E_ALL | E_STRICT);
$okay= TRUE;
$relationship= $_POST['relationship'];
$interests= $_POST['interests'];
$history= $_POST['history'];
$occupation= $_POST['occupation'];
$name= $_POST['name'];
if($name == 'david')
{
session_start();
$_SESSION[$father_relationship] = $relationship;
$_SESSION[$father_interests] = $interests;
$_SESSION[$father_occupation] = $occupation;
$_SESSION[$father_name] = $name;
$_SESSION[$father_history] = $history;
include 'david.php';
exit();
}
david.php
<?php // david.php
// Define Variables
$father_name = $_SESSION[$father_name];
$father_relationship = $_SESSION[$father_relationship];
$father_interests = $_SESSION[$father_interests];
$father_history = $_SESSION[$father_history];
$father_occupation = $_SESSION[$father_occupation];
//print father's information
print"<h3>Relationship to Chris</h3>
<p>$father_relationship</p>
<h3>History</h3>
<p>$father_history</p>
<h3>Occupation</h3>
<p>$father_occupation</p>
<h3>Interests</h3>
<p>$father_interests</p>";
?>
It is necessary that the Session be Set/Active in all the Files that need access to the Data that were set using $_Session and setting the session should be the very first thing on any script that needs to access data stored in the Session Global Variable....
HTML FILE:
<div>
<form action="handle_family.php" method="post">
<p>Family Member: <select name="name">
<option value="david">David</option>
<option value="linda">Linda</option>
<option value="cayla">Cayla</option>
<option value="sophie">Sophie</option>
<option value="sawyer">Sawyer</option>
</select></p>
<p>Relationship: <select name="relationship">
<option value="father">Father</option>
<option value="mother">Mother</option>
<option value="wife">Wife</option>
<option value="son">Son</option>
<option value="daughter">Daughter</option>
</select></p>
<p>Interests: <input type="text" name="interests" size="60" /></p>
<p>History: <input type="text" name="history" size="60" /></p>
<p>Occupation: <input type="text" name="occupation" size="60" /></p>
<input type="submit" name="submit" value="Update Page" />
</form>
</div>
handle_family.php FILE:
<?php // NOTICE THAT THERE IS NOT WHITE-SPACE BEFORE <?php
// Script 6.2 - handle_reg.php
// FILE-NAME: handle_reg.php WHERE YOU HAVE TO SET THE SESSION VARIABLE
//FIRST CHECK IF SESSION EXIST BEFORE STARTING IT:
if (session_status() == PHP_SESSION_NONE || session_id() == '') {
session_start();
}
if(!isset($_SESSION['familyTree'])){
$_SESSION['familyTree'] = array();
}
if(isset($_POST['submit'])) {
ini_set('display_errors', 1);
error_reporting(E_ALL | E_STRICT);
$okay = TRUE;
$relationship = htmlspecialchars(trim($_POST['relationship']));
$interests = htmlspecialchars(trim($_POST['interests']));
$history = htmlspecialchars(trim($_POST['history']));
$occupation = htmlspecialchars(trim($_POST['occupation']));
$name = htmlspecialchars(trim($_POST['name']));
// STORE EACH NAME IN THE SESSION USING THE LOWER-CASED FATHERS-NAME AS A UNIQUE KEY
$lcName = strtolower($name);
$_SESSION['familyTree'][$lcName]['father_name'] = $name;
$_SESSION['familyTree'][$lcName]['father_history'] = $history;
$_SESSION['familyTree'][$lcName]['father_interests'] = $interests;
$_SESSION['familyTree'][$lcName]['father_occupation'] = $occupation;
$_SESSION['familyTree'][$lcName]['father_relationship'] = $relationship;
if ($lcName == 'david') {
include 'david.php';
exit();
}
}
david.php FILE:
<?php // NOTICE THAT THERE IS NOT WHITE-SPACE BEFORE <?php
// FILE-NAME: david.php
//FIRST CHECK IF SESSION EXIST BEFORE STARTING IT:
if (session_status() == PHP_SESSION_NONE || session_id() == '') {
session_start();
}
$name = "david"; // MAKE SURE THIS IS LOWER-CASE...
$fatherInfo = "";
if(!isset($_SESSION['familyTree'][$name])) {
// Define Variables
$father_name = $_SESSION['familyTree'][$name]['father_name'];
$father_history = $_SESSION['familyTree'][$name]['father_history'];
$father_interests = $_SESSION['familyTree'][$name]['father_interests'];
$father_occupation = $_SESSION['familyTree'][$name]['father_occupation'];
$father_relationship = $_SESSION['familyTree'][$name]['father_relationship'];
//print father's information
$fatherInfo = "<h3>Relationship to Chris</h3>" . PHP_EOL;
$fatherInfo.= "<p>$father_relationship</p>" . PHP_EOL;
$fatherInfo.= " <h3>History</h3>" . PHP_EOL;
$fatherInfo.= "<p>$father_history</p>" . PHP_EOL;
$fatherInfo.= " <h3>Occupation</h3>" . PHP_EOL;
$fatherInfo.= "<p>$father_occupation</p>" . PHP_EOL;
$fatherInfo.= " <h3>Interests</h3>" . PHP_EOL;
$fatherInfo.= "<p>$father_interests</p>" . PHP_EOL;
}
echo $fatherInfo;

How to output all checkbox value

hello please help me i have a problem outputting all the values of checkbox it outputs only one i need to show all the checked checkbox and output them please help me here is the code it only shows one whenever i checked them all i need this
<html>
<head>
<title>Cake Form</title>
<link rel="stylesheet" href="cakeform.css">
</head>
<body>
<?php
$nameErr = $addErr = $phoneErr = $scake = $flavorcake = $fill = "";
$name = $address = $phone = $rcake = $fillr = $cakeflavor = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["name"])) {
$nameErr = "Name is required";
} else {
$name = test_input($_POST["name"]);
}
if (empty($_POST["address"])) {
$addErr = "Email is required";
} else {
$address = test_input($_POST["address"]);
}
if (empty($_POST["phone"])) {
$phoneErr = "Gender is required";
} else {
$phone = test_input($_POST["phone"]);
}
if(isset($_POST['SelectedCake'])){
$x=$_POST['SelectedCake'];
}
if(isset($_POST['CakeFlavor'])){
$y=$_POST['CakeFlavor'];
}
if(isset($_POST['Filling'])){
$z=$_POST['Filling'];
}
if(empty($x)){
$scake='Select one Cake';
}else{
$rcake= $x;
}
if(empty($y) OR $y == 'Flavor'){
$flavorcake='Select one flavor';
}else{
$cakeflavor= $y;
}
if(empty($z)){
$fill='Select at least one Fillings';
}else{
foreach($z as $item){
$fillr=$item;
}
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<div id="wrap">
<div class="cont_order">
<fieldset>
<legend>Make your own Cake</legend>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post">
<h4>Select size for the Cake:</h4>
<input type="radio" name="SelectedCake" value="Round6">Round cake 6" - serves 8 people</br>
<input type="radio" name="SelectedCake" value="Round8">Round cake 8" - serves 12 people</br>
<input type="radio" name="SelectedCake" value="Round10">Round cake 10" - serves 16 people</br>
<input type="radio" name="SelectedCake" value="Round12">Round cake 12" - serves 30 people</br>
<span class="error">*<?php echo $scake;?></span>
<h4>Select a Cake Flavor: </h4>
<select name="CakeFlavor">
<option value="Flavor" selected="selected">Select Flavor</option>
<option value="Carrot" >Carrot</option>
<option value="Chocolate" >Chocolate</option>
<option value="Banana" >Banana</option>
<option value="Red Velvet" >Red Velvet</option>
<option value="Strawberry" >Strawberry</option>
<option value="Vanilla" >Vanilla</option>
<option value="Combo" >Combo</option>
</select>
<span class="error">*<?php echo $flavorcake;?></span>
<h4>Select Fillings:</h4>
<label><input type="checkbox" name="Filling[]" value="Cream"/>Cream</label><br>
<label><input type="checkbox" name="Filling[]" value="Fudge"/>Fudge</label><br>
<label><input type="checkbox" name="Filling[]" value="Ganache"/>Ganache</label><br>
<label><input type="checkbox" name="Filling[]" value="Hazelnut"/>Hazelnut</label><br>
<label><input type="checkbox" name="Filling[]" value="Mousse"/>Mousse</label><br>
<label><input type="checkbox" name="Filling[]" value="Pudding"/>Pudding</label><br>
<span class="error">*<?php echo $fill;?></span>
</fieldset>
</div>
<div class="cont_order">
<fieldset>
<legend>Contact Details</legend>
<label for="name">Name</label><br>
<input type="text" name="name" id="name"><span class="error">*<?php echo $nameErr;?></span>
<br>
<label for="address">Address</label><br>
<input type="text" name="address" id="address"><span class="error">*<?php echo $addErr;?></span>
<br>
<label for="phonenumber">Phone Number</label><br>
<input type="text" name="phone" id="phone"><span class="error">*<?php echo $phoneErr;?></span><br>
</fieldset>
<input type="submit" name="submitted" id="submit" value="Submit"/>
</div>
</form>
<div class="cont_order">
<?php
echo $name.'<br>';
echo $address.'<br>';
echo $phone.'<br>';
echo $rcake.'<br>';
echo $cakeflavor.'<br>';
echo $fillr.'<br>';
?>
</div>
</div>
</body>
</html>
You can do this:
var_dump($_POST['Filling']);
Or just this:
<?php
if(!empty($_POST['Filling'])) {
foreach($_POST['Filling'] as $check) {
echo $check;
}
}
?>
Tell me if it works =)
Fact is, you accept a list for filling.
In your code you do this :
foreach($z as $item){
$fillr=$item;
}
Replace it by :
$fillr = '';
foreach($z as $item){
$fillr .= '- ' . $item . '<br/>';
}
It should work better.
For comment :
#so let's say $z is an array :
$z = [1,2,3,4];
#then you say, for each element of the array as you will call $item, I do something
foreach($z as $item){
$fillr=$item; #here you say : for each element of $z (1,2,3,4), I put this value into $fillr.
}
#so let's do the loop together.
# First pass, $item == 1, so $fillr == 1.
# Second pass, $item == 2, so $fillr == 2.
# ...
# Last pass, $item == 4, so $fillr == 4.
# so then when you show $fillr it's the last item of the list (here 4).
# using PHP, .= means concatenate.
# for instance :
$a = "hello ";
$a .= "world";
echo $a;
> hello world
So basically, what I'm doing is :
Having an empty string I'll call $fillr.
For every element of the list,
Append "the_element plus a <br/>" to $fillr
so then when you output $fillr it looks sexy.
Do you get it bud?

wordpress form with roster registration of users

I'm trying to build a manual form on a Wordpress page.
My goal is to create a dropdown menu of all the users with a fixed role (in my case "athlete") and register single users in some sport events.
My code:
<form name="team_captain" method="POST" >
Carnival Name: <input type="text" id="carnival_name" name="carnival_name" />
<input type="submit" name="submit_carnival" value="Create Carnival"/><br />
Event Name: <select name="event_name">
<option value="Ironman Race">Ironman Race</option>
<option value="Board Race">Board Race</option>
<option value="Ski Race">Ski Race</option>
<option value="Surf Race">Surf Race</option>
</select><br />
Athlete Name:
<select name="athlete_name">[insert_php] echo getUsersByRole('athlete','athlete-selector'); [/insert_php]</select><br />
Age Group: <select name="age_group">
<option value="Under 15">Under 15</option>
<option value="Under 17">Under 17</option>
<option value="Under 19">Under 19</option>
<option value="Open">Open</option>
</select><br />
Sex: <input type="radio" name="athlete_sex" value="Male">Male <input type="radio" name="athlete_sex" value="Female">Female<br />
<input type="submit" value="Insert Race"/>
</form>
[insert_php]
if(isset($_POST['submit_carnival'])) {
$carnival_name = $_POST['carnival_name'];
echo "Registrations for ".$carnival_name;
}
elseif(isset($_POST['submit'])) {
$event_name = $_POST["event_name"];
$athlete_sex = $_POST["athlete_sex"];
$age_group = $_POST["age_group"];
$athlete_name = $_POST["athlete_name"];
echo $event_name;
echo $age_group;
echo $athlete_sex;
echo $athtlete_name;
}
[/insert_php]
At this point I can display the name of the carnival, but I can't display the instances of the athletes. And the dropdown list of the athletes doesn't work.
This is the function:
function getUsersByRole($role,$name,$selected = '',$extra = '') {
global $wpdb;
$wp_user_search = new WP_User_Query(array("role"=> $role));
$role_data = $wp_user_search->get_results();
foreach($role_data as $item){
$role_data_ids[] = $item->ID;
}
$ids = implode(',', $role_data_ids);
$r = $wpdb->get_results("SELECT * from ".$wpdb->prefix . "users where id IN(".$ids .")", ARRAY_A);
$content .='<select name="'.$name.'" id="'.$name.'" '.$extra.'>';
if($selected == ''){
$content .='<option value="" selected="selected">Choose a user</option>';
}else{
$r_user = $wpdb->get_results("SELECT * from ".$wpdb->prefix . "users where ID = ".$selected."", ARRAY_A);
$content .='<option value="'.$selected.'" selected="selected">'.stripslashes($r_user[0]['display_name']).'</option>';
}
for($i=0; $i<count($r); $i++){
$content .='<option value="'.$r[$i]['ID'].'">'.stripslashes($r[$i]['display_name']).'</option>';
}
$content .='</select>';
return $content;
}
Because you're looking for a $_POST["submit"], you'll have to have an input with the name attribute equal to submit. In your case replace this:
<input type="submit" value="Insert Race"/>
with this:
<input type="submit" name="submit" value="Insert Race"/>
Your getUsersByRole() function is already including the "select" tag, so replace this line:
<select name="athlete_name">[insert_php] echo getUsersByRole('athlete','athlete-selector'); [/insert_php]</select><br />
with this, notice that I changed "athlete-selector" to "athlete_name":
[insert_php] echo getUsersByRole('athlete','athlete_name'); [/insert_php]<br />
With those two changes, things should be working, though I haven't studied your getUsersByRole() function intensively, so there could be a bug in there. Let me know in a comment below if this works for you or not.

Search multiple words and single word at a time in a multiple row in Mysql php

I'm trying to use this search for searching more than one words or single word at a time from a database. Now the problem is that my script only running properly but please help me...
<form name="ds" method="post">
<input type="text" name="name" placeholder="Entername" />
<!--<input type="text" name="search" placeholder="Location" />-->
<select name="location[]" multiple="multiple">
<option value="delhi">Delhi</option>
<option value="Mumbai">Mumbai</option></select>
<input type="submit" name="submit" value="Search" />
</form>
<?
$conn=mysql_connect("localhost","root","");
mysql_select_db("dbrozgarexpress",$conn);
echo $search =$_POST['location'];
$description = "";
$name2=$_POST['name'];
if(isset($name2)&&$name2 != ""){
if($flag){
$cheack.= "AND ";
}
$cheack.="user_first_name ='$name2' ";
$flag =true;
}
if(isset($search)&&$search != ""){
if($flag){
$cheack.= "AND ";
}
foreach($search AS $s)
{
$cheack.="user_current_location_id ='$s' or ";
$flag =true;
}
}
$cheack = substr($cheack, 0, -4);
echo $query = "SELECT * FROM `tb_user` WHERE $cheack ";
?>
error SELECT * FROM `tb_user` WHERE user_first_name ='kum
I think I have a general idea of what you are after.
P.S. the query will only show after you submit the form - i.e. after you click search button
Try this:
<?php
// Handle Post
if (count($_POST))
{
// Load Params
$name = isset($_POST['name']) ? $_POST['name'] : '';
$locations = isset($_POST['location']) ? $_POST['location'] : array();
// Start Query
$sql = 'SELECT * FROM `tb_user` WHERE ';
// Build Query
$sql_parts = array();
if (!empty($name)) {
$sql_parts[] = "`user_first_name` = '$name'";
}
if (sizeof($locations)) {
foreach ($locations as $location) {
$sql_parts[] = "`user_current_location_id` = '$location'";
}
}
$sql = $sql . implode(' AND ', $sql_parts);
// Debug
echo $sql ."<br><br>";
}
?>
<form action="" name="ds" method="post">
<input type="text" name="name" placeholder="Entername" />
<select name="location[]" multiple="multiple">
<option value="delhi">Delhi</option>
<option value="Mumbai">Mumbai</option></select>
<input type="submit" name="submit" value="Search" />
</form>
Here's an example of this working:
No location selected, name only
name and one location
name and two location

Categories