Multiselect Search with PDO - php

I would like to list the selected options. But there are 3 separate selectbox. "Brand", "Fuel" and "Gear". For example, when I select ford brand, it is listed but if I select fuel and gear with brand, I get a wrong list. How should it be?
DATABASE MEANING
TABLE (araclar = "CARS TABLE") arac_marka = "BRANDS" arac_vites = "GEAR" arac_benzin = "FUEL"
AND FORM ACTION (SELF)
<form action="" method="get">
<div class="col-xs-12 col-sm-3 col-md-3">
<select name="arac_marka" class="form-control">
<option value="">Marka Seçin</option>
<? $marsor=$db->prepare('SELECT * FROM araclar');
$marsor->execute();
while ($marcek=$marsor->fetch(PDO::FETCH_ASSOC)){ ?>
<option value="<?=$marcek['arac_marka'];?>">
<?=$marcek['arac_marka'];?>
</option>
<? } ?>
</select>
</div>
<div class="col-xs-12 col-sm-3 col-md-3">
<select name="arac_benzin" class="form-control">
<option value="">Yakıt Tipi</option>
<option value="Benzin">Benzin</option>
<option value="Dizel">Dizel</option>
<option value="Hybrid">Hybrid</option>
<option value="LPG">LPG</option>
</select>
</div>
<div class="col-xs-12 col-sm-3 col-md-3">
<select name="arac_vites" class="form-control">
<option value="">Vites</option>
<option value="Benzin">Otomatik</option>
<option value="Dizel">Manuel</option>
<option value="Hybrid">Yarı Otomatik</option>
</select>
</div>
<div class="col-xs-12 col-sm-2 col-md-3 col-lg-2">
<input class="btn btn-primary" type="submit" name="dtara" value="Filtrele">
</div>
<div class="col-xs-12 col-sm-2 col-md-3 col-lg-2">
Tüm Araçlar
</div>
</form>
AND LISTING
<? if(isset($_GET['dtara'])) {
$marka=$_GET['arac_marka'];
$benzin=$_GET['arac_benzin'];
$vites=$_GET['arac_vites'];
$asql=$db->prepare("SELECT * FROM araclar
WHERE arac_marka='$marka'
OR arac_benzin='$benzin'
OR arac_vites='$vites'");
$asql->execute();
} else {
$asql=$db->prepare('select * from araclar');
$asql->execute();
}
while ($acek=$asql->fetch(PDO::FETCH_ASSOC)){?>
//Listing Here
<? } ?>

Related

Convert a text field to a selection field drop-down lists

the following code shows a text field for the user to write their city, I would like to convert that text field into a selection field with a drop-down list. My knowledge in php is very basic, I appreciate you can help me.
The code is located in a PHP template of a user profile.
<?php
global $current_user;
wp_get_current_user();
$userID = $current_user->ID;
$user_login = $current_user->user_login;
$state = get_the_author_meta( 'user_state' , $userID );
?>
<div class="row">
<div class="col-md-12">
<div class="couple-profile-main-block dashboard-box">
<form id="user-profile" class="ajax-auth form-horizontal" method="post">
<div class="status"></div>
<?php wp_nonce_field('ajax-user-profile-nonce', 'security'); ?>
<div class="row">
<div class="col-md-6">
<div class="form-group row">
<div class="col-sm-4"><label><?php esc_html_e('State','theme');?>*</label></div>
<div class="col-sm-8"><input class="form-control" id="state" name="state" type="text" value="<?php echo esc_attr($state);?>"></div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="row">
<div class="col-sm-offset-4 col-sm-8"><button id="couple-profile-on" class="btn btn-pink"><?php esc_html_e('Update Profile','theme');?></button></div>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
You’ll need to switch out that text-input to a select input - check out https://www.w3schools.com/tags/tag_select.asp
In your case, something like this should replace where the text input is.
<select class="form-control" id="state" name="state">
<option value=“State1” <?php if ($state == “State1”) echo “selected”; ?>>State 1</option>
<option value=“State2” <?php if ($state == “State2”) echo “selected”; ?>>State 2</option>
<option value=“State3” <?php if ($state == “State3”) echo “selected”; ?>>State 3</option>
</select>

How to push action form with variable of select?

I want to take value from select in html and push it into action url.
So when users select something value of action buyoption will be the value of the selection
I would prefer to do it with php if there is no option to do it with html.
This is my test buy it doesn't change the buyoption to selection variable..
please help
<form action="<?php echo URLROOT; ?>/trades/trade/buyoption/selloption" method="POST">
<div class="row">
<div class="col-md-9 register-right" >
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">
<h3 class="register-heading">TRADE</h3>
<div class="row register-form">
<div class="col-md-12">
<label for="buy"><b>YOU SEND:</b></label>
<div class="form-group">
<select class="form-control" name="buyoption" id="buyoption">
<option class="hidden" selected disabled>Please select what you want to sell</option>
<option value="btc">Bitcoin (BTC)</option>
<option value="ltc">LITECOIN (LTC)</option>
<option value="eur">NATIONAL BANK TRANSFER (EUR/USD/HRK)</option>
</select>
</div>
<label for="buy"><b>YOU RECEIVE:</b></label>
<div class="form-group">
<select class="form-control" name="selloption" id="buyoption">
<option class="hidden" selected disabled>Please select what you want receive</option>
<option value="btc">Bitcoin (BTC)</option>
<option value="ltc">Litecoin (LTC)</option>
<option value="eur">NATIONAL BANK TRANSFER (EUR/USD/HRK)</option>
</select>
</div>
<input type="submit" class="btnRegister" value="Proceed"/>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
There must not be multiple elements in a document that have the same id value.
You can watch for change event of select element and on Change, manipulate the Action URL.
let buyoption = document.getElementById('buyoption');
let selloption = document.getElementById('selloption');
let postForm = document.getElementById('postForm');
let action = postForm.getAttribute('action');
let replacerFn = function() {
let temp = action;
if (buyoption.value) {
temp = temp.replace('buyoption', buyoption.value);
}
if (selloption.value) {
temp = temp.replace('selloption', selloption.value);
}
postForm.setAttribute('action', temp);
console.log('Action Attribute=> ', postForm.getAttribute('action'));
};
buyoption.addEventListener('change', function() {
replacerFn();
});
selloption.addEventListener('change', function() {
replacerFn();
});
<form action="/trades/trade/buyoption/selloption" method="POST" id="postForm">
<div class="row">
<div class="col-md-9 register-right">
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">
<h3 class="register-heading">TRADE</h3>
<div class="row register-form">
<div class="col-md-12"> <label for="buy"><b>YOU SEND:</b></label>
<div class="form-group">
<select class="form-control" name="buyoption" id="buyoption">
<option class="hidden" selected disabled value="">Please select what you want to sell</option>
<option value="btc">Bitcoin (BTC)</option>
<option value="ltc">LITECOIN (LTC)</option>
<option value="eur">NATIONAL BANK TRANSFER (EUR/USD/HRK)</option>
</select>
</div><label for="buy"><b>YOU RECEIVE:</b></label>
<div class="form-group">
<select class="form-control" name="selloption" id="selloption">
<option class="hidden" selected disabled value="">Please select what you want receive</option>
<option value="btc">Bitcoin (BTC)</option>
<option value="ltc">Litecoin (LTC)</option>
<option value="eur">NATIONAL BANK TRANSFER (EUR/USD/HRK)</option>
</select>
</div><input type="submit" class="btnRegister" value="Proceed" /> </div>
</div>
</div>
</div>
</div>
</div>
</form>

how to filter and validate select option in form using PHP

$batch = htmlentities($_POST['batch']);
if($batch === 'NULL'){
echo "Batch Failed";
} else {
echo "$bacth";
}
<div class="col-md-12">
<div class="form-group">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-globe"></i></span>
<select class="form-control" name="batch" id="select">
<option selected disabled>Batch Preference</option>
<option value="Weekends">Weekends</option>
<option value="Holidays">Holidays</option>
</select>
</div>
</div>
</div>
How to select those select options in form using php, how i can validate them...
Thank You

How to get the selected dropdown value using jQuery

I want to get the selected value in dropdown for edit. But I got all the values in dropdown are selected.
function getinstruments() {
var model=$('#model').val();
var brand=$('#brand').val();
brand = brand.split('%') ;
model = model.split('%') ;
$.getJSON("{!! URL::route('appraisal.getinstrument') !!}", {brand: brand[0],model:model[0]}, function(data) {
if(data.success)
{
$('select[name="sub_model"]').find(":selected").html(data.sub_models_array);
$('select[name="color"]').find(":selected").html(data.colors_array);
$('select[name="top"]').find(":selected").html(data.top_array);
$('select[name="neck"]').find(":selected").html(data.neck_array);
}
});
}
Don't know what the problem with this code is. Reply of the question is highly appreciated
<div class="col-lg-6 col-xsm-6">
<h4>Enter Body wood details</h4>
<div class="form-group">
<label>Top Wood</label>
<select name='top_wood' class='form-control' placeholder ='Enter Top wood' id='top'>
<option value=''>Pick a topWood</option>
</select>
</div>
<div class="form-group">
<label>Back Woord</label>
<select name='back_wood' class='form-control' placeholder ='Enter Back wood' id='back'>
<option value=''>Pick a topWood</option>
</select>
</div>
<div class="form-group">
<label>Neck Wood</label>
<select name='neck_wood' class='form-control' placeholder ='Enter Neck wood' id='neck'>
<option value=''>Pick a NeckWood</option>
</select>
</div>
<div class="form-group">
<label>Select color</label>
<select name='color' class='form-control' id='color' >
<option value=''>Pick a color</option>
</select>
</div>
<div class="form-group">
<label>Frets</label>
<select name='frets' class='form-control' placeholder ='Enter Frets' id='frets'>
<option value=''>Pick a Fingerboard Material</option>
</select>
</div>
<div class="form-group">
<label>Turner</label>
<select name='turner' class='form-control' placeholder ='Enter Turner' id='turner'>
<option value=''>Pick a Fingerboard Material</option>
</select>
</div>
this is my view file where i want selected value of dropdaown

php how do I make a textbox unchangeable or passive and a syntax error [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 6 years ago.
ive been all around trying to fix the code but i still get an error
Parse error: syntax error, unexpected 'userfirstName' (T_STRING), expecting ',' or ';' in /home/crosswayprinting/public_html/ztest2/functions/shop.php on line 66
here's the code btw
whats my mistake :/ ?
<?php if($user_home->is_logged_in()){
echo '
<div class="row">
<div class="col-lg-8 col-lg-offset-2">
<h2 class="section-heading">Place an Order</h2>
<div class="text-center" style="input, select, textarea{
color: #000;
}">
</div><BR>
<form role="form" class="userTrans" method="POST">
<input type="hidden" value="OrderInsert" name="act_userTrans">
<div class="form-group">
<label for="typeofservice">Select Type of Service</label>
<select id="typeofservice" class="form-control" name="typeofservice">
<option value="Tarpaulin">Tarpaulin</option>
<option value="Rush ID">Rush ID</option>
<option value="Photocopy">Photocopy</option>
<option value="Graphic Layout">Graphic Layout</option>
<option value="Invitation">Invitation</option>
<option value="Panaflex">Panaflex</option>
<option value="Signages">Signages</option>
<option value="Stickers">Stickers</option>
<option value="Sintra board">Sintra board</option>
<option value="Large Format Photo">Large Format Photo</option>
<option value="PVC ID">PVC ID</option>
<option value="Lamination">Lamination</option>
<option value="Bag Tags">Bag Tags</option>
<option value="Notary Public">Notary Public</option>
<option value="Scan">Scan</option>
</select>
</div>
<div class="form-group">
<label for="templateselect">Template Selection</label>
<select id="templateselect" class="form-control" name="templateselect">
<option value="Own Made Template">Own Made Template</option>
<option value="Pre-made Template">Pre-made Template</option>
</select>
</div>
<div class="form-group">
<label for="text">More details about your order</label>
<input type="text" class="form-control" id="orderdetails" name="orderdetails">
</div>
<div class="form-group">
<label for="text"> Customer Name</label>
<input type="text" value=" <?php echo $row['userfirstName']; ?> " class="form-control" id="customer" name="customer">
</div>
/* this is the code btw what makes it an error, i am trying to
echo a customer's name and make it Passive or uneditable textbox so it can
register to my orderlist to whom ordered */
<button type="submit" class="btn btn-default userTrans">Submit</button>
</form>
';
}
else{
echo '
<center> Please Login to Place an Order </center>
';}
?>
Get rid of the echo statements wrapping your HTMl. There's no need, just escape out of the PHP interpreter and print your HTML. Then you won't get an error when you're doing <?php echo $row['userFirstName']; ?>....Something like this:
<?php if($user_home->is_logged_in()){ ?>
<div class="row">
<div class="col-lg-8 col-lg-offset-2">
<h2 class="section-heading">Place an Order</h2>
<form role="form" class="userTrans" method="POST">
<input type="hidden" value="OrderInsert" name="act_userTrans">
<div class="form-group">
<label for="typeofservice">Select Type of Service</label>
<select id="typeofservice" class="form-control" name="typeofservice">
<option value="Tarpaulin">Tarpaulin</option>
<option value="Rush ID">Rush ID</option>
<option value="Photocopy">Photocopy</option>
<option value="Graphic Layout">Graphic Layout</option>
<option value="Invitation">Invitation</option>
<option value="Panaflex">Panaflex</option>
<option value="Signages">Signages</option>
<option value="Stickers">Stickers</option>
<option value="Sintra board">Sintra board</option>
<option value="Large Format Photo">Large Format Photo</option>
<option value="PVC ID">PVC ID</option>
<option value="Lamination">Lamination</option>
<option value="Bag Tags">Bag Tags</option>
<option value="Notary Public">Notary Public</option>
<option value="Scan">Scan</option>
</select>
</div>
<div class="form-group">
<label for="templateselect">Template Selection</label>
<select id="templateselect" class="form-control" name="templateselect">
<option value="Own Made Template">Own Made Template</option>
<option value="Pre-made Template">Pre-made Template</option>
</select>
</div>
<div class="form-group">
<label for="text">More details about your order</label>
<input type="text" class="form-control" id="orderdetails" name="orderdetails">
</div>
<div class="form-group">
<label for="text"> Customer Name</label>
<input type="text" value=" <?php echo $row['userfirstName']; ?> " class="form-control" id="customer" name="customer">
<!-- now the above won't give an error -->
</div>
<button type="submit" class="btn btn-default userTrans">Submit</button>
</form>
</div>
</div>
<?php } else { ?>
<!-- Do not use center tags when you're using bootstrap framework -->
<!--<center> Please Login to Place an Order </center>-->
<div class="text-center"> Please Login to Place an Order </div>
<?php } ?>
Also what's going on with your inline styles? That's not how this works:
<div class="text-center" style="input, select, textarea{
color: #000;
}">
Just move that CSS somewhere else. You can't use targeted selectors within the style="" tag, only relevant CSS.

Categories