values not saving in database - php

Once we click on Button, i am trying to update values in Database & along with that i need to download pdf....
once values [tracking_id] are updated in database, than only i can able to download pdf....
When i click on button its not updating tracking_id column in database.... instead it showing 0....
shippinglabel.php Full code in pastebin
<?php
$db_handle2= new DBController();
$star="select pincode , xpressbee from shippment_details where xpressbee='xpressbee' and pincode='$pinc'";
$resultstar = $db_handle2->runSelectQuery($star);
if($resultstar)
{
if($orderrecords[$k]["tracking_id"]==''){
?>
<input type="button" name="shipment" id="xpress" value="xpress"
onclick="createshipment('<?php echo $orderrecords[$k]["order_id"]; ?>')" />
<?php }}
?>
<?php
if($orderrecords[$k]["tracking_id"]!='' && $orderrecords[$k]["shipping_name"]=='xpress')
{?>
<a target="_blank"
href="/ecom1/xpress/xpressdownload.php?orderId=<?php echo $orderrecords[$k]["order_id"]; ?>"
id="pdfdownload" >
<input type="button" name="shipment" value="DOWNLOAD" /></a>
<?php }?>
<Script>
function createshipment(orderid)
{
var assignee='<?php echo $_SESSION['login_user']?>';
alert(orderid);
$.ajax({
url: "xpressshipment.php",
type: "POST",
data:'orderid='+orderid+'&assignee='+assignee,
success: function(data){
if(data==1)
{
$("#pdfdownload").show();
$("#ekartc").hide();
}
if(data==2){alert("order id not proper.");}
if(data==0){alert("First Enter Tracking Id.");}
window.location ="/ecom1/xpress/xpressdownload.php?orderId="+orderid;
//location.reload();
}
});
}
xpressshipment.php Full code in pastebin
<?php
$data =
array (
'OrderNo' => $order_id,
'AirWayBillNO' => $resultc[0]['awb'],
);
$data = json_encode($data);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$curl_response = curl_exec($curl);
curl_close($curl);
echo $curl_response ."\n";
$res=json_decode($curl_response);
if($res->AddManifestDetails[0]->ReturnMessage=='successful')
{
$sqli="update do_order set tracking_id='".$resultc[0]['awb']."',shipping_name='xpress' , current_status='99' where order_id='".$order_id."'";
$resulti=$db_handle->executeUpdate($sqli);
$sqlj = "update ecomexpress_awb set orderid = '".$order_id."',status='assigned' WHERE awb ='".$resultc[0]['awb']."'";
$resultj = $db_handle->runSelectQuery($sqlj);
}
xpressdownload.php Full code in pastebin
<?php
if(isset($_GET['orderId']) && $_GET['orderId']!='')
{
$orderid=$_GET['orderId'];
}
else
{
echo 2;
}
$sqlorder = "SELECT comments,tracking_id,order_id,order_date,address,product_type,alternateno,sku,customer_email,price,customer_name,phone_number,payment_type,product_name from do_order where order_id='".$orderid."' limit 1";
$resultdoorder = $db_handle->runSelectQuerys($sqlorder);
if($resultdoorder['tracking_id']=='')
{
echo "0";
}
else
{
// pdf download code
}

Related

Search Box to retrieve data using Ajax and PHP

Below is the index page: having these code: Data gets populated in a div as expected.
<h2>Search for users</h2>
<input type="text" name="search" id="search" autocomplete="off" placeholder="Enter Customer ID here....">
<div id="output"></div>
<script type="text/javascript">
$(document).ready(function(){
$("#search").keyup(function(){
var query = $(this).val();
if (query != "") {
$.ajax({
url: 'ajax-db-search.php',
method: 'POST',
data: {query:query},
success: function(data){
$('#output').html(data);
$('#output').css('display', 'block');
$("#search").focusin(function(){
$('#output').css('display', 'block');
});
}
});
} else {
$('#output').css('display', 'none');
}
});
});
</script>
This is the ajax-db-search.php page. (In the IF tags I tried it with == and no good luck yet.)
<?php
$conn=mysqli_connect("*****","*********","******","*****");
$query = "SELECT * FROM `create_customer` WHERE `Customer Id` LIKE '{$_POST['query']}%' LIMIT 6";
$result = mysqli_query($conn, $query);
$plan = $query['Plan'];
if ($plan = "planA") {
while ($user = mysqli_fetch_array($result)) {
echo "<h2>".$user['Customer Name']."</h2>";
echo "<h4><a href='http://smjw.phatake.in/admin/cc.php?recordID=".$user['id']."'>Update Profile Details</a></h4>";
echo "<h4><a href='http://smjw.phatake.in/admin/planA_details.php?recordID=".$user['Customer Id']."'>Receive Payment</a></h4>";
var_dump ($plan);
}
}
if ($plan = "planB") {
while ($user = mysqli_fetch_array($result)) {
echo "<h2>".$user['Customer Name']."</h2>";
echo "<h4><a href='http://smjw.phatake.in/admin/cc.php?recordID=".$user['id']."'>Update Profile Details</a></h4>";
echo "<h4><a href='http://smjw.phatake.in/admin/planB_details.php?recordID=".$user['Customer Id']."'>Receive Payment</a></h4>";
}
}
if ($plan = "planC") {
while ($user = mysqli_fetch_array($result)) {
echo "<h2>".$user['Customer Name']."</h2>";
echo "<h4><a href='http://smjw.phatake.in/admin/cc.php?recordID=".$user['id']."'>Update Profile Details</a></h4>";
echo "<h4><a href='http://smjw.phatake.in/admin/planC_details.php?recordID=".$user['Customer Id']."'>Receive Payment</a></h4>";
}
}
if ($plan = "planA1") {
while ($user = mysqli_fetch_array($result)) {
echo "<h2>".$user['Customer Name']."</h2>";
echo "<h4><a href='http://smjw.phatake.in/admin/cc.php?recordID=".$user['id']."'>Update Profile Details</a></h4>";
echo "<h4><a href='http://smjw.phatake.in/admin/planA1_details.php?recordID=".$user['Customer Id']."'>Receive Payment</a></h4>";
}
}
else {
echo "<p style='color:red'>User not found...</p>";
}
?>
The Problem is with the If condition: The Url's that needs to be displayed on my index page should change according to the $plan variable. But for some reason the $plan variable is always planA..
There are 4/5 Plans.. planA, planB, planc, planA1 each having different Urls that needs to displayed.
The URL do get populated but will be always the First IF conditions URL for all the customers.
Please help me out with this. Stuck for big time.
-------Update-------------
I want each of the Receive Payment to be according to the if conditions.. Now its all only planA
Here i am using php pdo for perform the search task.
i am create a two file 'search.php' is a send ajax request to query.php file.
search.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Search</title>
<!-- jQuery cdn link -->
<script src="https://code.jquery.com/jquery-3.6.0.js" integrity="sha256-H+K7U5CnXl1h5ywQfKtSj8PCmoN9aaq30gDh27Xc0jk=" crossorigin="anonymous"></script>
</head>
<body>
<input type="text" id="search" placeholder="Search">
<div class="table-div" style="display: none"></div>
</body>
</html>
<script>
$(document).ready(function(){
$("#search").keyup(function(){
$.get("/query.php", {data:$(this).val()}, function(data, status){
let row = JSON.parse(data);
let table = "";
table += "<table>";
table += "<thead>";
table += "<tr>";
table += "<th>Customer name</th><th>Customer salary</th>";
table += "</tr>";
table += "</thead>";
table += "<tbody>";
if(row.data != "No data found") {
$.each(row.data, function(key, value){
table += "<tr>";
table += "<td>"+ value.customer_name +"</td>";
table += "<td>"+ value.cust_sal +"</td>";
table += "</tr>";
});
}
table += "</tbody>";
table += "</table>";
$(".table-div").html(table);
$(".table-div").show();
});
});
});
</script>
query.php
<?php
// This is a database connectivity
$conn = new PDO("mysql:host=localhost; dbname=test;", 'root', '');
if(isset($_GET['data']))
{
$query = "%".$_GET['data']."%";
$searchSQL = "SELECT * FROM cust WHERE customer_name LIKE :cname";
$searchState = $conn->prepare($searchSQL);
$searchState->bindParam(":cname", $query);
if($searchState->execute())
{
if($searchState->rowCount() > 0)
{
$data = $searchState->fetchAll();
}
else
{
$data = "No data found";
}
}
echo json_encode(["data" => $data]);
}
?>
Hmm you said you tried == it should be == and not =.
Firstly please note your sql queries any kind of query should be prepare statements even if you trust your users.
Now please note that:
echo "planA"=="plana" ? "yes" : "no"; // Output no. Have you tried this?
Edit: I overlooked " But for some reason the $plan variable is always planA.." that is because of = in your ifs
$plan = "";
if ($plan = "a") {
echo $plan;
}
if ($plan = "b") {
echo $plan;
}
if ($plan = "c") {
echo $plan;
}
//output: abc
Lastly, please use else if, you don't need to check if 3 times it can only be 1 option.
Edit 2: I think you have some way to go. Please have look at the code below.
Here is the complete working with your bug I think:
<?php
// Since I have no post i will set it by default
$_POST['query'] = 'AZ12';
// Check for data validation...
if (!isset($_POST['query']) || empty($_POST['query'])) return;
// Now for query
$query = "SELECT * FROM `create_customer` WHERE `Customer Id` LIKE ? LIMIT 6";
// Prepare the statement to insert user_answer in ? above
// replace "s" based on your appropriate var type
$stmt = $conn->prepare($query);
// $stmt->bind_param("s", "%".$_POST['query']."%"); <-- This would yield error
// ^ fix: Store the 2nd param first
$like = "%{$_POST['query']}%";
$stmt->bind_param("s", $like);
$stmt->execute();
// Get the results
$result = $stmt->get_result();
echo "<br/>";
print_r($result);
// Output: mysqli_result Object ( [current_field] => 0 [field_count] => 3 [lengths] => [num_rows] => 1 [type] => 0 )
// ^ This will show all the elements part of $result (your case 6)
// Why this? Because to me it seems like you have hard-coded plans
// because if $plan = A,B,C and then you insert while loop inside the if's
$plans = array(0 => 'PlanA', 1 => 'PlanB', 2 => 'PlanC');
foreach($plans as $value) {
echo "<h1>$value</h1><br/>";
// Now loop as assoc like you have...
while ($row = $result->fetch_assoc()) {
print_r($row);
// ^ With above get the data value you need such as:
// echo "<h2>".$row['Customer Id']."</h2>";
}
// Add this to fix the fetch_assoc
$result->data_seek(0); // without this you will see the image below
}
// ^ Output Notice we only show plan A rows!!! look image below.
// Fix indicate by $result->data_seek(0);
?>
I am assuming this is what you get: "Why only A show?"

Value showing empty in browser , but its available in Database

Once we click on Download button, we are trying to download complete order details in pdf.... here 100452121 is orderid, xpress is shipping name & 14104918100111 is tracking id....
we set conditions that if tracking_id is empty, than it should echo 0 but we are getting zero [0] even when tracking_id available for the order....
Shippinglabel.php Full code in pastebin
<td><?php echo $orderrecords[$k]["order_id"]; ?><br/>
<?php
if ($st == 1) {
if ($orderrecords[$k]["tracking_id"] == '') {
?>
<input type="button" name="shipment" id="xpress" value="xpress"
onclick="createshipment('<?php echo $orderrecords[$k]["order_id"];?>')" />
<?php
}
}
?>
<?php
if ($orderrecords[$k]["tracking_id"] != '' && $orderrecords[$k]["shipping_name"] == 'xpress')
{
?>
<a target="_blank"
href="http://sbdev1.kidsdial.com/ecom1/xpress/xpressdownload.php?orderId=<?php
echo $orderrecords[$k]["order_id"];?>"
id="pdfdownload" >
<input type="button" name="shipment" value="DOWNLOAD" /></a>
<?php
}
?>
</td>
createshipment
function createshipment(orderid)
{
var assignee='<?php echo $_SESSION['login_user']?>';
alert(orderid);
$.ajax({
url: "xpressshipment.php",
type: "POST",
data:'orderid='+orderid+'&assignee='+assignee,
success: function(data){
if(data==1)
{
$("#pdfdownload").show();
}
if(data==0){alert("First Enter Tracking Id.");}
window.location ="http://sbdev1.kidsdial.com/ecom1/xpress/xpressdownload.php?orderId="+orderid;
}
});
}
xpressshipment.php Full code in pastebin
<?php
$data =
array (
'AirWayBillNO' => $resultc[0]['awb'],
);
if($res->AddManifestDetails[0]->ReturnMessage=='successful')
{
$sqli="update do_order set tracking_id='".$resultc[0]['awb']."',shipping_name='xpress' where order_id='".$order_id."'";
$resulti=$db_handle->executeUpdate($sqli);
}
?>
xpressdownload.php Full code in pastebin
<?php
if(isset($_GET['orderId']) && $_GET['orderId']!='')
{
$orderid=$_GET['orderId'];
}
else
{
echo 2;
}
$orderid='';
$sqlorder = "SELECT tracking_id,order_id from do_order where order_id='".$orderid."' limit 1";
$resultdoorder = $db_handle->runSelectQuerys($sqlorder);
if($resultdoorder['tracking_id']=='')
{
echo 0;
//var_dump("tracking_id");
}
var_dump("tracking_id"); gave string(11) "tracking_id" as result....
please let me know if you need more details....
please help me to find solution....
Thanks in Advance....
In file xpressdownload.php you defined variable $orderid incorrectly.
if(isset($_GET['orderId']) && $_GET['orderId']!='')
{
$orderid=$_GET['orderId'];
}
else
{
echo 2;
}
$orderid='';
First, you are checking whether $_GET['orderId'] exists and if yes, you give the value of $_GET['orderId'] to $orderid. This is correct.
But after the if... else block you give the $orderid the '' value. So in every case the $orderid has the null value and you sql query is not returning the record. You have to remove the line $orderid=''; or move it before the if statement.

Save WooCommerce Order details in custom table

I have created a custom database in table order-master in which I will save WooCommerce order total amount, shipping charges and token.
For this, I have edited paypemts.php file, code is below:
<?php
include_once($_SERVER['DOCUMENT_ROOT'].'/canadiapharma.com/wp-config.php' );
global $woocommerce;
global $wpdb;
echo '<h3>Custom Calculation :</h3>';
$amount_2 = $woocommerce->cart->get_cart_total();
$ship_raw = floatval( preg_replace( '#[^\d.]#', '', $woocommerce->cart->get_cart_shipping_total() ) );
$ship = $ship_raw - 3600;
echo '<strong>Shipping :</strong>';
echo $ship;
$nano=WC()->cart->cart_contents_total;
echo '<br>';
$total_amt = $nano+$ship;
echo '<strong>Total :</strong>';
echo $total_amt;
echo '<br>';
$salt = 'dAta_EnC!=';
$token_raw = base64_encode($total_amt. $salt);
$token = preg_replace(sprintf('/=/', $salt), '', $token_raw);
echo '<strong>Token :</strong>';
echo $token;
$wpdb->query("INSERT INTO order_master (payment_amt, ship, token) VALUES ('$total_amt', '$ship', '$token')" );
?>
This code works fine and stores the data to the database. But it stores the data as soon as the checkout.php page loads. So, I made some changes and created an onclick event on Place Order button in checkout.php page.
OnCLick Event:
<?php echo apply_filters( 'woocommerce_order_button_html', '<button type="submit" class="button alt" name="woocommerce_checkout_place_order" id="place_order" value="' . esc_attr( $order_button_text ) . '" data-value="' . esc_attr( $order_button_text ) . '" onclick="dbinsert()">' . esc_html( $order_button_text ) . '</button>' );
?>
dbinsert():
<script>
function dbinsert() {
var myKeyVals = { amount : <?php echo $total_amt; ?>., ship : <?php echo $ship; ?>., token : <?php echo $token; ?> }
var saveData = $.ajax({
type: 'POST',
url: "savedata.php",
data: myKeyVals,
dataType: "text",
success: function(dbinsert) { alert("Save Complete") }
});
saveData.error(function() { alert("Something went wrong"); });
}
</script>
onclick event executes perfectly but doesn't know why data is not going into the database. Below is my savedata.php file.
<?php
global $wpdb;
$total_amt = $_POST['amount'];
$ship = $_POST['ship'];
$token = $_POST['token'];
$stmt = $wpdb->query("INSERT INTO order_master (payment_amt, ship, token) VALUES ('$total_amt', '$ship', '$token')" );
$stmt->bindparam('payment_amt', $total_amt);
$stmt->bindparam('ship', $ship);
$stmt->bindparam('token', $token);
if($stmt->execute())
{
$res="Data Inserted Successfully:";
echo json_encode($res);
}
else {
$error="Not Inserted,Some Probelm occur.";
echo json_encode($error);
}
?>
Please help me to fix this issue.
Try by changing your ajax url url: "savedata.php", to url: "<?php echo admin_url('admin-ajax.php?action=save_order_data');?>" and add below code in your theme's function.php
add_action('wp_ajax_nopriv_save_order_data', 'save_order_data');
add_action('wp_ajax_save_order_data', 'save_order_data');
function save_order_data() {
global $wpdb;
$total_amt = $_POST['amount'];
$ship = $_POST['ship'];
$token = $_POST['token'];
$stmt = $wpdb->query("INSERT INTO order_master (payment_amt, ship, token) VALUES ('$total_amt', '$ship', '$token')" );
$result = $wpdb->query($wpdb->prepare($stmt));
if($result)
{
$res="Data Inserted Successfully:";
echo json_encode($res);
}
else {
$error="Not Inserted,Some Probelm occur.";
echo json_encode($error);
}
}
Updated:
There is an error in var myKeyVals = { amount : <?php echo $total_amt; ?>., ship : <?php echo $ship; ?>., token : <?php echo $token; ?> }. Change your var myKeyVals as below:
var myKeyVals = { amount : "<?php echo $total_amt; ?>",
ship : "<?php echo $ship; ?>",
token : "<?php echo $token; ?>" }
You need to write php code in "" in javascript.
Hope this helps.

How to fill a template file with data from a table

I am looking for some initial direction on this one because I cannot seem to find my way with it. Let me explain... I'm creating a music website and having a search bar. It filters information as the user types. I don't want to make a separate .php file for each song on the website. (Eg: song1.php, song2.php, etc...). There should be one PHP template file, that outputs the webpage for ALL songs. With my code, when I try searching with the search bar, it opens the template file as expected but it fills the file with information of only the first row from the mysql table. This is the form, its in the index page:
<script type = "text/javascript "src = "jquery.js">
<form class="navbar-form navbar-left" >
<div class="form-group">
<input type="text" class="form-control" id="search" placeholder="Search for songs, artists" autocomplete="off">
<div id = "searchresults"> </div>
Then there's the search.js file having two tasks, that is to check if a result has been clicked and also if the user has pressed a key. Its like this:
$('#search').keyup(function()
{
var searchterm = $ ('#search').val();
if (searchterm != '')
{
$.post('search.php', {searchterm:searchterm},
function(data)
{
$('#searchresults').html(data);
});
}
else{
$('#searchresults').html('');
}
});
$('#mylink').click(function(){
var wanted = $('#mylink').val();
$.post('/web/ztemplate.php', {wanted:wanted});
});
I think it's the one having an error but I can't figure out where it is. The template file has this php code :
$search = $_POST['wanted'];
$find = mysql_query("SELECT * FROM search WHERE title LIKE '%$search%'");
$row = mysql_fetch_assoc($find); $title = $row["title"];
There's a search.php file which queries the database to provide information for the instant search. It looks like this :
$search = mysql_real_escape_string(trim($_POST['searchterm']));
if ($search == '' && ' '){
echo 'No results found';
}
else {
$find_videos = mysql_query("SELECT * FROM search WHERE keywords LIKE '%$search%'");
$count = mysql_num_rows($find_videos);
if ($count ==0){
echo 'No Results found for '.$search;
}
else {
while($row = mysql_fetch_assoc($find_videos)){
$title = $row["title"];
$link = $row["link"];
echo "<a href = '$link'><h5 id = 'mylink'> $title <h5> </a> <hr /> ";
}
}
}
Any help is much appreciated.
why you not send an AJAX??
$('#search').keyup(function(){
var searchterm = $ ('#search').val();
if (searchterm != ''){
$.ajax({
type: 'POST',
data: {
"searchterm": searchterm,
"_token":"{{ csrf_token() }}"
},
url: "{{URL::asset('yourPHP')}}",
success: function(response){
$('#searchresults').html(response);
}
});
}else{
$('#searchresults').html('');
}
});
PHP
function searchSong($search =''){
$search = (trim($_POST['searchterm']));
$out='';
if ($search == '' && ' '){
echo 'No results found';
}else {
$sql = "SELECT * FROM search WHERE title LIKE '%$search%'";
$data= DB::select($sql);
$count = count($data);
if ($count ==0){
echo 'No Results found for '.$search;
}else {
foreach ($data as $key => $row) {
$title = $row["title"];
$link = $row["link"];
$out .= "<a href = '$link'><h5 id = 'mylink'> $title </h5> </a> <hr /> ";
}
}
}
return $out;
}

Filtering a jQuery ListView using Checkbox

I have jQuery ListView that loads data from a php file. I also have a checkbox that onclick should be able to filter the list. The filtering is done by sending a post message to server and refreshing the list. However, the checkbox list is not filtering the list. The code below is only part of the whole implementation. Here is the page:
http://i.cs.hku.hk/~hsbashir/Project_Work/Listview/restaurant_list.html
This is the HTML implementation:
<head>
<script>
lastRecord=0;
function loadRest(){
$('#sample').html( 'hello' );
$.get(
"queryRestaurantsList.php?lastRecord="+lastRecord,
function( data ) {
$('#rest_mesgs').append( data )
.listview( 'refresh' );
}
);
}
</script>
</head>
<body onload="loadRest()">
<div data-demo-html="true">
<form>
<fieldset data-role="controlgroup" data-type="horizontal">
<legend>Select your type of Restaurant:</legend>
<input type="checkbox" name="checkbox-h-2a" id="checkbox-h-2a" onchange="onfilter()" value="Vegetarian"/>
<label for="checkbox-h-2a">Vegetarian</label>
</fieldset>
</form>
</div>
<div data-demo-html="true">
<ul data-role="listview" data-theme="a" data-split-theme="b" data-split-icon="plus" data-inset="true" id="rest_mesgs">
<li data-role="list-divider">Restaurants</li>
</ul>
</div>
<script>
function onfilter(){
if($("#checkbox-h-2a").prop('checked')){
document.getElementById("hehe").innerHTML = "if condition is true";
var a = document.getElementById("checkbox-h-2a");
$.post("queryRestaurantsList.php",
{
filter0 : a.value;
},
function(data){
$('#rest_mesgs').append( data )
.listview( 'refresh' );
});
}
else {
document.getElementById("hehe").innerHTML = "not working";
}
}
</script>
</body>
This is php file:
mysql_connect($host,$username,$password);
mysql_select_db($database) or die( "Unable to select database");
//Check if POST array is empty or not
if ($_POST == null){
$query = "SELECT Name,Short_Loc,Image_Link,Type FROM Restaurant_Info";
$result = mysql_query($query) or die( "Unable to execute query");
while ($row = mysql_fetch_array($result)){
print '<li>';
print '<a href="'.$row['Full_Link'].'">';
print '<img style="height:80px;" src="'.$row['Image_Link'].'">';
print '<h2 style="text-wrap : normal">'.$row['Name'].'</h2>';
print '<p id="type" class="ui-li-aside"><strong>'.$row['Type'].'</strong></p>';
print '<p>'.$row['Short_Loc'].'</p>';
print '</a>';
print '</li>';
}
}
else {
$value1 = $_POST[filter0];
$query0 = 'SELECT Name,Short_Loc,Image_Link FROM Restaurant_Info WHERE Type LIKE ';
$query0 = $query0.'"%'.$value1.'%"';
$result = mysql_query($query0) or die( "Unable to execute query");
$num_results = mysql_num_rows($result);
if ($num_results == 0){
print "Your criteria does not match any of the restaurants";
}
else{
while($row = mysql_fetch_array($result)) {
print '<li>';
print '<a href="'.$row['Full_Link'].'">';
print '<img style="height:80px;" src="'.$row['Image_Link'].'">';
print '<h2 style="text-wrap : normal">'.$row['Name'].'</h2>';
print '<p>'.$row['Short_Loc'].'</p>';
print '</a>';
print '</li>';
}
}
I can see 2 errors, but unfortunately I can't test them.
1 - This php part:
else {
$value1 = $_POST[filter0];
Should be replace with:
else {
$value1 = $_POST['filter0'];
Otherwise filter0 will be treated as a constant instead of a string.
2 - On your html, you did:
<input type="checkbox" name="checkbox-h-2a" id="checkbox-h-2a" onchange="onfilter()" value="Vegetarian"/>
This should be
<input type="checkbox" name="checkbox-h-2a" id="checkbox-h-2a" onclick="onfilter()" value="Vegetarian"/>
I think a checkbox won't fire onchange when you check or uncheck it.
1 . To maintain checkbox state change use jQuery.toggle(). It's the safest way.
$("#checkbox-h-2a").toggle(function(){
var filter = $(this).val();
getListviewItems({filter0: filter});
}, function() {
getListviewItems();
});
2 . Make one function with params for getting list items. That way you'll keep your code clean and easy to maintain.
function getListviewItems(opt) {
opt.filter0 = (opt.filter0 == undefined)?'':opt.filter0;
/* Body of function, post and/or get calls, etc. */
}

Categories