Pagination query not working - php

I have a problem in my pagination. My scenario is I'll just the filters then click search. Then the result will show the output. But when I click on page 2 it returns to the query for all not the query that is filtered.
Controller
<?php //CONTROLLER
function maintenance(){
if($this->session->userdata('l#ginUs3r')) {
$session_data = $this -> session -> userdata('l#ginUs3r');
$data['u_id'] = $session_data['u_id'];
$data['u_uname'] = $session_data['u_uname'];
$data['u_pword'] = $session_data['u_pword'];
$data['u_role'] = $session_data['u_role'];
$data['is_active'] = $session_data['is_active'];
$config = array();
$config["base_url"] = base_url() . "personnel/maintenance/";
$config["total_rows"] = $this -> Main -> count_prf();
$config["per_page"] = 10;
$config["uri_segment"] = 3;
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data['prf'] = $this -> Main -> select_prf($config['per_page'], $page);
$data["prf_links"] = $this->pagination->create_links();
if(isset($_POST['search']))
{
if($_POST['division'] != "" && $_POST['group'] != "" && $_POST['department'] != "" && $_POST['position'] != "" )
{
if($_POST['date_rec'] != "" && $_POST['date_upto'] != "")
{
$where = "prf_div = '".$_POST['division']."' AND prf_group = '".$_POST['group']."' AND prf_status = '".$_POST['prf_status']."' AND prf_dept = '".$_POST['department']."' AND prf_position = '".$_POST['position']."' AND prf_status = '".$_POST['prf_status']."' AND prf_daterec BETWEEN '".$_POST['date_rec']."' AND '".$_POST['date_upto']."' ";
}
else
{
$where = "prf_div = '".$_POST['division']."' AND prf_group = '".$_POST['group']."' AND prf_status = '".$_POST['prf_status']."' AND prf_dept = '".$_POST['department']."' AND prf_position = '".$_POST['position']."' AND prf_status = '".$_POST['prf_status']."' ";
}
}
//NEXT IF FOR SEARCH
if($_POST['division'] == "" && $_POST['group'] == "" && $_POST['department'] == "" && $_POST['position'] == "" )
{
if($_POST['date_rec'] != "" && $_POST['date_upto'] != "")
{
$where = "prf_status = '".$_POST['prf_status']."' AND prf_daterec BETWEEN '".$_POST['date_rec']."' AND '".$_POST['date_upto']."' ";
}
else
{
$where = "prf_status = '".$_POST['prf_status']."' ";
}
}
$_SESSION['page_list'] = $where;
$config = array();
$config["base_url"] = base_url() . "personnel/maintenance/";
$config["total_rows"] = $this -> Main -> count_prf_where($_SESSION['page_list']);
$config["per_page"] = 10;
$config["uri_segment"] = 3;
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data["prf"] = $this -> Main -> fetch_prf($_SESSION['page_list'], $config["per_page"], $page);
$data["prf_links"] = $this->pagination->create_links();
}
$this -> load -> view('templates/header', $data);
$this -> load -> view('pages/maintenance', $data);
$this -> load -> view('templates/footer');
} else {
$this -> load -> view('templates/lheader');
$this -> load -> view('pages/login');
$this -> load -> view('templates/footer');
}
}
?>
View
<button type="button" class="btn btn-success btn-search-cust1 pull-right" onclick="window.location.href='<?=base_url()?>personnel/add_prf'"><span class="icon-file"></span></button>
<button type="button" name="back" class="btn btn-success btn-search-cust pull-right" onclick="window.location.href='<?=base_url()?>personnel/home'"> <span class="icon-home"></span> </button>
<?php $this -> load -> view('templates/maintenance-navbar'); ?>
<article class="grid_12 panel">
<div class=""><span class=""> </span><label class="listnames">Filter</label></div>
<div class="tab-field">
<form method="POST" action="<?=base_url()?>personnel/maintenance">
<label class="listnames">Division</label>
<select class="cust_fields" name="division">
<option value="">--Select--</option>
<?php if(!$ddl2){ ?>
<option value=""><?="NO DATA"?></option>
<?php } else { ?>
<?php foreach($ddl2 as $row){ ?>
<option value="<?=$row['d_id']?>"><?=$row['d_divname']?></option>
<?php } ?>
<?php } ?>
</select>
<label class="listnames">Group</label>
<select class="cust_fields" name="group">
<option value="">--Select--</option>
<?php if(!$ddl2){ ?>
<option value=""><?="NO DATA"?></option>
<?php } else { ?>
<?php foreach($ddl1 as $row){ ?>
<option value="<?=$row['g_id']?>"><?=$row['g_name']?></option>
<?php } ?>
<?php } ?>
</select>
<label class="listnames">PRF Status<!--FORMERLY ROLE --></label>
<select name="prf_status" id="roles" class="cust_fields">
<option value="Outstanding">Outstanding</option>
<option value ="Served">Served</option>
</select>
<br>
<label class="listnames">Department</label>
<select name="department" id="roles" class="cust_fields">
<option value="">--Select--</option>
<?php if(!$ddl3){ ?>
<option value=""><?="NO DATA"?></option>
<?php } else { ?>
<?php foreach($ddl3 as $row){ ?>
<option value="<?=$row['dept_id']?>"><?=$row['dept_name']?></option>
<?php } ?>
<?php } ?>
</select>
<label class="listnames">Position</label>
<select name="position" id="roles" class="cust_fields">
<option value="">--Select--</option>
<?php if(!$ddl5){ ?>
<option value=""><?="NO DATA"?></option>
<?php } else { ?>
<?php foreach($ddl5 as $row){ ?>
<option value="<?=$row['r_id']?>"><?=$row['r_rank']?></option>
<?php } ?>
<?php } ?>
</select>
<label class="listnames">Date Received</label>
<input type="date" name="date_rec" placeholder="mm/dd/yyyy" id="fromdate" autocomplete="off" style="height: 24px; width: 128px;">
<label class="listnames" style = "width: 15px;">To</label>
<input type="date" name="date_upto" placeholder="mm/dd/yyyy" id="fromdate" autocomplete="off" style="height: 24px; width: 128px;">
<button type="submit" name="search" class="btn btn-success cust_search"><span class="icon-search2"></span></button>
<!-- <input type="submit" name="search" value="Search"> -->
</form>
</div>
</article>
<table class="table">
<tr class="thead1" style = "background: #D6C9A4;">
<div class="row">
<div class="col-md-3">
<div class="row"><div class="col-md-3"><th >Division</th></div><div class="col-md-3"><th >Group</th></div><div class="col-md-3"><th >Department</th></div></div>
</div>
<div class="col-md-3">
<div class="row"><div class="col-md-3"><th >Position</th></div><div class="col-md-3"><th >Rank</th></div><div class="col-md-3"><th >Ex. No. of Personnel</th></div></div>
</div>
<div class="col-md-3">
<div class="row"><div class="col-md-3"><th >No. of Req. Personnel</th></div><div class="col-md-3"><th >No. of Served Personnel</th></div><div class="col-md-3"><th >Reason for PRF</th></div></div>
</div>
<div class="col-md-3">
<div class="row"><div class="col-md-3"><th >Date Received</th></div><div class="col-md-3"><th >Date Served</th></div><div class="col-md-3"><th >Age of PRF</th></div><div class="col-md-3"><th >PRF Status</th></div></div>
</div>
</div>
</tr>
<?php
if(!$prf)
{
?>
<h3 class="tab-field">No Data</h3>
<?php
}
$x = 1;
foreach($prf as $row){
$id = $row['prf_id'];
$now = time();
$your_date = strtotime($row['prf_daterec']);
$datediff = $now - $your_date;
$age = floor($datediff/(60*60*24));
$date_rec = substr($row['prf_daterec'], 0, -13);
$date_serv = substr($row['prf_dateserv'], 0, -13);
?>
<tr id="active" onclick="window.location.href='<?=base_url()?>personnel/prf_info/<?=$id?>'">
<td><?=strtoupper($row['d_divname'])?></td>
<td><?=strtoupper($row['g_name'])?></td>
<td><?=strtoupper($row['dept_name'])?></td>
<td><?=strtoupper($row['prf_position'])?></td>
<td><?=strtoupper($row['r_rank'])?></td>
<td><?=strtoupper($row['prf_ex_no_personnel'])?></td>
<td><?=strtoupper($row['prf_no_req_personnel'])?></td>
<td>Served Personnel</td>
<td><?=strtoupper($row['prf_reason'])?></td>
<td><?=$date_rec?></td>
<td><?=$date_serv?></td>
<td><?=$age?> Days</td>
<td><?=$row['prf_status']?></td>
</tr>
<?php } ?>
</table>
<div class="pagination-align"><?=$prf_links?></div>

Related

How do i post a $_GET variable value using a REQUEST METHOD

I am trying to post a $_GET value so it cant insert the variable value into the database using $_SERVER["REQUEST_METHOD"].
<?php require_once("../includes/initialize.php"); ?>
<?php include("../includes/form_validation_card.php"); ?>
<?php $username = $_SESSION['username']; ?>
<?php
if(!isset($_GET['total']) && !isset($_GET['order_id'])){
redirect_to('order_summary.php');
}
$total = $_GET['total'];
$order = $_GET['order_id'];
?>
<?php
$username = $_SESSION['username'];
$sql = "SELECT * FROM customers WHERE username='$username'";
$result_set = $database->query($sql);
$found_user = $database->fetch_array($result_set);
?>
<?php include_layout_template('header2.php'); ?>
<div class="container">
<div class="row">
<br/><br/><?php echo output_message($message); ?>
</div>
<div class="row ">
<div class="jumbo jumbotron-fluid mx-auto d-block" style="height: 500px; width: 440px; background-color:#DCDCDC; border-radius: 5px;" >
<div class="text-center" style="margin: 3px;"><img src="logo/eden_petshop_logo.png" width="32" height="32"/><?php echo $found_user['first_name']; ?> <?php echo $found_user['last_name']; ?></div>
<p class="text-center">order id: #<?php echo $order; ?></p>
<h4 class="display-4 lead text-center">N<?php echo $total; ?></h4>
<div class="col-sm-6 col-sm-offset-3 mx-auto d-block">
<?php echo output_message($message); ?>
<form action="<?= $_SERVER['PHP_SELF']; ?>" method="post" class="form-horizontal">
<div class="form-group">
<div class="col">
<input type="text" name="card_number" onchange="trim(this)" placeholder="Card Number" class="form-control" id="card_number"/>
<span style="color: #EA4335"><?= $card_number_error; ?></span>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col">
<input type="text" name="mm_yy" class="form-control" onchange="trim(this)" placeholder="MM/YY">
<span style="color: #EA4335"><?= $mm_yy_error; ?></span>
</div>
<div class="col">
<input type="password" name="cvv" class="form-control" onchange="trim(this)" placeholder="CVV">
<span style="color: #EA4335"><?= $cvv_error; ?></span>
</div>
</div>
</div>
<div class="col-sm-12 col-sm-push-3">
<button type="submit" name="submit" value="Pay" class="btn bg-info btn-sm btn-block" onClick="return confirm('Are you sure your details are correct?');">Pay</button>
</div>
</form>
</div>
</div>
</div>
<?php include_layout_template('footer2.php'); ?>
This is the input display page but i am trying to the $total and $order $_GET variables insert into the database... Please note that every other part of the code assignment is working fine.
<?php
//define variables and set them to empty values
$total_error = $order_error = $card_number_error = $mm_yy_error = $cvv_error = "";
$timestamp = strftime("%Y-%m-%d %H:%M:%S", time());
//form is submitted with post method
if($_SERVER["REQUEST_METHOD"] == "POST"){
if(empty($_POST["card_number"])){
$card_number_error = "<div class=''>Card number is required</div>";
}else{
$card_number = test_input($_POST["card_number"]);
//Check if name only contains letters and whitespaces
if(!preg_match("/^(?=.*?[0-9]).{16,}$/",$card_number)){
$card_number_error = "<div>Only 16 numbers allowed</div>";
}
}
if(empty($_POST["mm_yy"])){
$mm_yy_error = "<div class=''>Card expiry is required</div>";
}else{
$mm_yy = test_input($_POST["mm_yy"]);
//Check if name only contains letters and whitespaces
if(!preg_match("/^(?=.*?[0-9]).{3,}$/",$mm_yy)){
$mm_yy_error = "<div class=''>Only numbers allowed</div>";
}
}
if(empty($_POST["cvv"])){
$cvv_error = "<div class=''>Card verification is required</div>";
}else {
$cvv = test_input($_POST["cvv"]);
//check if username is atleast 7 characters
if(!preg_match("/^(?=.*?[0-9]).{3,}$/",$cvv)){
$cvv_error = "<div class=''>Card verification must not be more than 3 numbers</div>";
}
}
if($card_number_error == "" && $mm_yy_error == "" && $cvv_error == ""){
$token = 'vfjhvbkebecbjDRCWVJEcbkrvlnke24tir7c_zdvbejw968350124';
$token = str_shuffle($token);
$token = substr($token, 0, 15);
$username = $_SESSION['username'];
$sql = "SELECT * FROM customers WHERE username='$username'";
$result_set = $database->query($sql);
$found_user = $database->fetch_array($result_set);
$email = $found_user['email_address'];
$pay = new Payment();
$pay->username = $username;
$pay->order_id = $order;
$pay->total = $total;
$pay->card_number = $card_number;
$pay->expiry = $mm_yy;
$pay->cvv = $cvv;
$pay->transaction_id = $token;
$pay->status = 0;
$pay->created_at = $timestamp;
if($pay->save()){
//$mail = new Mail();
//$mail->email_address = $email_address;
//$mail->send_transaction_confirmation();
unset($_SESSION['shopping_cart']);
$session->message('<div class="btn bg-success">Congratulations!!! Your order has been processed.</div>');
redirect_to('photos.php');
}
}
if(empty($_POST["message"])){
$message = "";
} else{
$message = test_input($_POST["message"]);
}
}
function test_input($data){
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
$data = htmlentities($data);
return $data;
}
?>
Please note that my $order and total are not getting inserted into my database... Any assistance on my preg_match would be appreciated... Thanks in advance.
You need to use $_POST in your broken code instead of $_GET. Notice your working code used $_POST instead, which is why it works.

How to validate checkbox in a for loop

I am creating a seat reservation system. In my system, the code check number of seats a bus contains then pass it inside a for loop. When a user pick 2 passengers, it means two seats will be booked. How can I validate the checkbox in the for loop depending on the number of passenger(s) selected.
Using the GUI for more explanation.
on the main page, 2 there indicates number of passenger(s) selected.
When you come to the second page where the values are passed to, you can see 2 Adults as the selected number of passengers. When you click on Submit Button it does not validate the checkbox based on the number of passenger(s) selected. And if I should put required in the checkbox it validates the whole checkbox since it is in a loop
$_SESSION['seat_no'] is the number of seat(s) a bus contains. Let assume a user that want to book a seat selected two passengers which means two seats is booked, how can I validate the checkbox based on the number of seat(s) selected?
Here is my code:
<?php
for ($i = 1; $i <= $_SESSION['seat_no']; $i++) {
if(in_array($i,$mseat)){
echo "<div class='checkbox_wrapper_pick'>
<label>".$i."</label>
</div>";
}else{
echo "<div class='checkbox_wrapper'>
<input type='checkbox' value=".$i." name='seat_book[]' />
<label>".$i."</label>
</div>";
}
}
?>
The full source code:
<?php include("header.php"); error_reporting(0); ?>
<?php
if(isset($_POST['submit'])){
$from = $_POST['from'];
$to = $_POST['to'];
$date = $_POST['d_date'];
$nop = $_POST['nop'];
$_SESSION['from'] = $from;
$_SESSION['to'] = $to;
$_SESSION['date'] = $date;
$_SESSION['nop'] = $nop;
$get = mysqli_query($mysqli,"SELECT * FROM routes WHERE present_loc = '$from' and destination = '$to' ");
while($roys = mysqli_fetch_array($get)){
//get bus details
$bno = $roys['bus_no'];
$ploc = $roys['present_loc'];
$des = $roys['destination'];
$time = $roys['dept_time'];
$_SESSION['time'] = $time;
$amt = $roys['amount'];
$_SESSION['amt'] = $amt;
$b = str_replace( ',', '',$_SESSION['amt'] );
if( is_numeric($b) ) {
$a = $b;
}
$bus = mysqli_query($mysqli,"select * from bus where bus_no = '$bno'");
while($bu = mysqli_fetch_array($bus)){
$_SESSION['model'] = $bu['model'];
$_SESSION['seat_no'] = $bu['seat_no'];
$_SESSION['ac'] = $bu['bus_type'];
$_SESSION['excess_luggage'] = $bu['excess_luggage'];
$_SESSION['more_legs'] = $bu['more_legs'];
$_SESSION['id'] = $bu['id'];
}
$coun = mysqli_query($mysqli, "select count(booking_id) as seat, seats from booking where bus_no = '$bno' and seats !='' GROUP by booking_id" );
$mseat = array();
while($e = mysqli_fetch_array($coun)){
$bseat = $e['seat'];
$mseat[] = $e['seats'];
}
//$seatss = array();
$seat_string = implode(",",$mseat);
//get seats
$couns = mysqli_query($mysqli, "select sum(counter) as seat from booking where bus_no = '$bno' and seats !='' GROUP by bus_no" );
$rseats = mysqli_fetch_array($couns);
$lseat = $rseats['seat'];
if($_SESSION['seat_no'] == $lseat){
$tell = " No more seat(s) available.";
}else{
$tell = $_SESSION['seat_no'] - $lseat. " Seat(s) remaining.";
}
}
}
?>
<!--Main layout-->
<main class="mt-5">
<!--Main container-->
<form action="details" method="POST">
<!--Grid row-->
<div class="row">
<div class="col-lg-12 title-header mb-3 mx-auto z-depth-1">
<div class="row">
<div class="col-lg-8">
<?php echo '<h2> '.$_SESSION['from']. ' to '. $_SESSION['to']. '</h2>'; ?><br/>
<b><?php echo $_SESSION['date']; ?> :: <?php if($_SESSION['nop'] < '2') { echo $_SESSION['nop'] . ' Adult'; }
elseif($_SESSION['nop'] > 1) { echo $_SESSION['nop'] . ' Adults'; }
?></b>
</div>
</div>
</div>
<div class="col-lg-12 mbody"> <label style="margin-left: 4%; font-weight:bolder; font-size:20px; color:#000;">Details </label> </div>
<div class="col-lg-12 mbody bg-white ">
<table class="table table_view" style = "width: 100%; margin-left: 4%; margin-right:4%;">
<tbody>
<tr>
<td><b><?php echo $_SESSION['model']; ?></b><br/><?php echo $_SESSION['from']. ' to '. $_SESSION['to']; ?>
<br/><?php if($_SESSION['ac'] == 'AC') { echo '<span class="alert-info ac">'. $_SESSION['ac'] .'</span>'; }
else{ echo '<span class="alert-warning">No AC</pan>'; } ?>
<?php if($_SESSION['more_legs'] == 'Yes') { echo '<span class="alert-info ac">More Leg Room</span>'; }
else{ echo '<span class="alert-warning no">More Leg Not Available</pan>'; } ?>
</td>
<td><b>Departing Time</b><br/><i class="fa fa-clock-o" aria-hidden="true"></i> <?php echo $_SESSION['time']; ?></td>
<td> <img id = "seatimg" src="../images/seatsLayout/av.gif" class="img-responsive"> <?php echo $tell; ?></td>
<td>Adult <b>₦<?php echo $_SESSION['amt']; ?></b></td>
</tr>
</tbody>
</table>
</div>
<div class="col-lg-12">
<div class="col-lg-12 mbody"> <label style="margin-left: 3%; font-weight:bolder; font-size:20px; color:#000;"><img id = "seatimg" src="../images/seatsLayout/av.gif" class="img-responsive"> Select Seat</label> </div>
<div class="row detail">
<!--Grid column-->
<div class="col-lg-7 animation slideUp" >
<div class="well" id="bus_seats_layout" >
<table class="table table-bordered" cellspacing = "1" id="seatstable">
<tr>
<td><img id = "driverimg" src="../images/seatsLayout/steering.png" class="img-responsive" width="25" height="25"></td>
<td colspan="2" rowspan="3">
<?php
for ($i = 1; $i <= $_SESSION['seat_no']; $i++) {
if(in_array($i,$mseat)){
echo "
<div class='checkbox_wrapper_pick'>
<label>".$i."</label>
</div>
";
}else{
echo "
<div class='checkbox_wrapper'>
<input type='checkbox' value=".$i." name='seat_book[]' />
<label>".$i."</label>
</div>
";
}
}
?>
</td>
</tr>
</table>
</div>
</div>
<div class="col-lg-5">
<ul class="bt">
<li><img src="../images/seatsLayout/seat_available.png" class="img-responsive"> Available</li>
<li><img src="../images/seatsLayout/picked.png" class="img-responsive"> Selected</li>
<li><img src="../images/seatsLayout/seat_booked.png" class="img-responsive"> Booked</li>
</ul>
</div>
</div>
<div class="col-lg-12">
<input type="hidden" name="bus_no" value="<?php echo $bno; ?>">
<input type="hidden" name="to" value="<?php echo $to; ?>">
<input type="hidden" name="from" value="<?php echo $from; ?>">
<input type="hidden" name="amt" value="<?php echo $nop*$a; ?>">
<input type="hidden" name="nop" value="<?php echo $nop; ?>">
<div class="form-group">
<div align="right">
<input type="submit" name="submit" class="bme" value="Continue">
</div>
</div>
</div>
</div>
</div>
</form>
</main>
<?php include("footer.php"); ?>

unable to submit the php form

i have three files
leaveform.php
leavefrom.tpl
leaveform.class.php
i will send the codings below. olease find and solve this issue.
leaveform.php
<?php
include_once 'init.php';
include CLASS_DIR."leaveform.class.php";
$leaveformObj = new leaveform;
$email = '';
$password = '';
$err_msg = '';
$s_msg = '';
$verfication_code = '';
if(isset($_POST['leaveSubmit'])){
$branch = $_POST['branch'];
$date = $_POST['date'];
$name = $_POST['name'];
$designation = $_POST['designation'];
$employeeid = $_POST['employeeid'];
$noofdays = $_POST['noofdays'];
$from = $_POST['from'];
$to = $_POST['to'];
$reasonforleave = $_POST['reasonforleave'];
$address = $_POST['address'];
$contactno = $_POST['contactno'];
$approvedby = $_POST['approvedby'];
if(empty($branch)){
$err_msg = "Please select your branch";
}elseif(empty($date)){
$err_msg = "Please select The Date";}
else {
$leaveformObj->branch = $branch;
$leaveformObj->date = $date;
$leaveformObj->name = $name;
$leaveformObj->designation = $designation;
$leaveformObj->employeeid = $employeeid;
$leaveformObj->noofdays = $noofdays;
$leaveformObj->from = $from;
$leaveformObj->to = $to;
$leaveformObj->reasonforleave = $reasonforleave;
$leaveformObj->address = $address;
$leaveformObj->contactno = $contactno;
$leaveformObj->approvedby = $approvedby;
$addleave = $leaveformObj->addleave(); //Login as Church Admin
if($addleave){
$leaveformObj->ticket_no = "Ticket#".$addleave;
$leaveformObj->leave_id = $addleave;
$Ticket = $leaveformObj->updateTicket();
if ($Ticket) {
$s_msg = "Successfully Submitted<br>";
$s_msg .= "Your Ticket No : Ticket#".$addleave;
}
}else{
$err_msg = "Invalid leaveform details";
}
}
}
$smarty->assign('s_msg', $s_msg);
$smarty->assign('err_msg', $err_msg);
$smarty->display('leaveform.tpl');
?>
leaveform.tpl
{include file="inc/main_header.tpl"}
<style type="text/css">
option {
text-transform: capitalize;
}
.nopadding div{
padding: 0px !important;
}
form[role="login"] input.inputText{
padding: 0;
border: 0;
background: none;
border-bottom: 1px dotted;
box-shadow: none;
border-radius: initial;
width: 85%;
}
form[role="login"] .threeCol input.inputText{
width: 68%;
}
</style>
<div class="wrapper">
<!-- Left side column. contains the logo and sidebar -->
<div class="container">
<div class="col-md-12">
<!--breadcrumbs start -->
<!--<ul class="breadcrumb front">
<li><i class="fa fa-home"></i> Home</li>
<li class="active">Admin Login</li>
</ul>-->
<!--breadcrumbs end -->
</div>
<section class="col-md-12">
<div class="panel panel-default">
<div class="panel-body">
<form method="post" action="" role="login" id="FormValidate">
<div class="col-md-3">
<img src="images/krishnasweet.png" alt="Krishna Sweet" class="" width='180'>
</div>
<div class="col-md-6">
<h3 style="text-align: center;color: blue;font-style: italic;">Leave Application Form<br></h3>
</div>
{if $s_msg}
<p style="text-align: center; color:green;">{$s_msg}</p>
{elseif $err_msg}
<p style="text-align: center; color:red;">{$err_msg}</p>
{/if}
<div class="col-md-12" style="min-height:30px;"></div>
<div class="col-md-3"> </div>
<div class="col-md-15" >
<div class="col-md-12 nopadding">
<div class="col-md-6"><label style="display: inline-block;">Branch :</label><input type="text" class="inputText" name="branch"></div>
<div class="col-md-6"><label style="display: inline-block;">Date :</label><input type="date" class="inputText" name="date"></div>
</div>
<div class="col-md--1"> </div>
</div>
<div class="col-md--1"> </div>
<div class="col-md--1" >
<div class="col-md--1">
</div>
</div>
<div class="col-md--1"> </div>
<div class="col-md-2" >
</div>
<div class="col-md-12 nopadding">
<div class="col-md-8"><label style="display: inline-block;">Name :</label><input type="text" class="inputText" name="name"></div>
<div class="col-md-8"><label style="display: inline-block;">Designation:</label><input type="text" class="inputText" name="designation"></div>
</div><div class="col-md-12 nopadding">
<div class="col-md-7"><label style="display: inline-block;">Employee ID :</label><input type="text" class="inputText" name="employeeid"></div>
</div>
<div class="col-md-12 threeCol nopadding">
<div class="col-md-4"><label style="display: inline-block;">No.Of.Days:</label><input type="text" class="inputText" name="noofdays"></div>
</div><div class="col-md-12 threeCol nopadding">
<div class="col-md-4"><label style="display: inline-block;">From:</label><input type="date" class="inputText" name="from" ></div>
<div class="col-md-4"><label style="display: inline-block;">To:</label><input type="date" class="inputText" name="to" ></div>
</div>
<div class="col-md-12 nopadding">
<div class="col-md-12"><label style="display: inline-block;">Reason For Leave:</label><input type="text" class="inputText" name="reasonforleave" "></div>
<div class="col-md-12"><label style="display: inline-block;">Address:</label><input type="text" class="inputText" name="address" "></div>
</div>
<div class="col-md-9"><label style="display: inline-block;">Contact No:</label><input type="text" class="inputText" name="contactno"></div>
<div class="col-md-9"><label style="display: inline-block;">Approved By:</label><input type="text" class="inputText" name="approvedby"></div>
</div>
<button type="submit" name="leaveSubmit" class="btn btn-block btn-info">Submit</button>
</form>
</div>
</div>
</section>
</div>
</div>
{include file="inc/main_footer.tpl"}
<script>
$(document).ready(function(){
$(document).on("change","#categorySection",function(event) {
var _val = $(this).val();
if(_val != ""){
$("#subCategorySection option").hide();
$("#subCategorySection option[data-cat="+_val+"]").show();
$("#subCategorySection").removeAttr("disabled");
}
});
});
</script>
leaveform.class.php
<?php
class leaveform
{
var $leave_id;
var $branch;
var $date;
var $name;
var $designation;
var $employeeid;
var $noofdays;
var $from;
var $to;
var $reasonforleave;
var $address;
var $contactno;
var $approvedby;
function complaints($leave_id = '')
{
global $db,$smarty;
if ( $leave_id )
{
$this->leave_id = $leave_id;
$sql = "SELECT * FROM leaveform WHERE leave_id=$this->leave_id";
$leaveform = $db->getRow($sql);
if($leaveform != null)
{
$this->leave_id = trim(stripslashes($leaveform['leave_id']));
$this->branch = trim(stripslashes($complaints['branch']));
$this->date = trim(stripslashes($complaints['date']));
$this->name = trim(stripslashes($complaints['name']));
$this->designation = trim(stripslashes($complaints['designation']));
$this->employeeid = trim(stripslashes($complaints['employeeid']));
$this->noofdays = trim(stripslashes($complaints['noofdays']));
$this->from = trim(stripslashes($complaints['from']));
$this->to = trim(stripslashes($complaints['to']));
$this->reasonforleave = trim(stripslashes($complaints['reasonforleave']));
$this->address = trim(stripslashes($complaints['address']));
$this->contactno = trim(stripslashes($complaints['contactno']));
$this->approvedby = trim(stripslashes($complaints['approvedby']));
}
}else {
$this->leave_id = "";
$this->branch = "";
$this->date = "";
$this->name = "";
$this->designation = "";
$this->employeeid = "";
$this->noofdays = "";
$this->from = "";
$this->to = "";
$this->reasonforleave = "";
$this->address = "";
$this->contactno = "";
$this->approvedby = "";
}
}
/***
Add Church Admin
Used Php Files : Index.php
***/
function addleave()
{
global $db, $smarty;
$sql = "INSERT INTO leaveform(branch,date,name,designation,employeeid,noofdays,from,to,reasonforleave,address,contactno,approvedby) VALUES
('$this->branch','$this->date', '$this->name','$this->designation','$this->employeeid','$this->noofdays','$this->from','$this->to','$this->reasonforleave','$this->address',
'$this->contactno','$this->approvedby')";
$result = $db->Execute($sql);
$leave_id = $db->insert_ID();
if($result)
{
return $leave_id;
}else{
return 0;
}
}
function updateTicket()
{
global $db, $smarty;
$sql = " UPDATE leaveform SET ticket_no = '$this->ticket_no' WHERE leave_id = '$this->leave_id' ";
$leave_id = $db->Execute($sql);
if($leave_id){
return true;
}else{
return false;
}
}
}
?>
i am using three php codes. i have a error with invalid details in php form.
kindly help me to solve this issue..and i am new to php
The failure is because of the below piece of Code. You are basically not setting the parameters correctly.
$sql = "INSERT INTO leaveform(branch,date,name,designation,employeeid,noofdays,from,to,reasonforleave,address,contactno,approvedby) VALUES
('$this->branch','$this->date', '$this->name','$this->designation','$this->employeeid','$this->noofdays','$this->from','$this->to','$this->reasonforleave','$this->address',
'$this->contactno','$this->approvedby')";
$result = $db->Execute($sql);
$leave_id = $db->insert_ID();
No one would go around debugging it for you. Turn on the "Show errors" options in your php.ini. The below link will help you.
https://www.inmotionhosting.com/support/website/php-troubleshooting/troubleshoot-php-errors
This will start showing the errors in the page itself and you should be able to debug.
Advice: Use PDO objects and bind every parameter to execute script in a cleaner way.

half data insert but remaining data not update that perticular session pass

there is data entered in foreach loop but not insert into database there is half data insert into database but there is no work foreach loop.....after insert half data , theres not update remaining half data.....why this happen
the code is
<?php
include_once('config.php');
if(isset($_POST["email_verify_btn"])) {
$email = $_POST["email_verify"];
$i = 1;
if(strpos($email,"\n")) {
$text = explode("\n",$email);
foreach ($text as $abc) {
$i++;
$status = 1;
$c_by = 1;
$c_date = date('Y-m-d H:i:s');
$c_ip = $_SERVER['REMOTE_ADDR'];
$_SESSION['date_time'] = $c_date;
$insert = $connect->query("INSERT INTO `email_verify_list`(`primary_email`,`session`,`status`,`created_by`, `created_date`, `created_ip`) VALUES ('$abc','".$_SESSION['date_time']."','$status','$c_by','$c_date','$c_ip')");
if($insert) {
$select_status = $connect->query("SELECT * from `email_verify_list` where session='".$_SESSION['date_time']."'");
$fetch_selected_status = $select_status->fetch_assoc();
$fetch_email= $fetch_selected_status['primary_email'];
if(filter_var($fetch_email, FILTER_VALIDATE_EMAIL)) {
function domain_exists($fetch_email)
{
$domain = substr(strrchr($fetch_email, "#"), 1);
$arr = #dns_get_record($domain, DNS_MX);
if ($arr[0]['host'] == $domain && !empty($arr[0]['target'])) {
return $arr[0]['target'];
}
}
if(domain_exists($fetch_email)){
$domain = substr(strrchr($fetch_email, "#"), 1);
$data = #dns_get_record($domain, DNS_MX);
if($data) {
$status = "email id is valid";
}
if (is_array($data) || is_object($data)) {
foreach ($data as $key1) {
$host = $key1['host'];
$target = $key1['target'];
$target_ip = gethostbyname($key1['target']);
}
}
} else {
$status = "mx recored not exist";
}
} else {
$status = "not in syntax" ;
}
$insert_all_data = $connect->query("UPDATE `email_verify_list` SET `host_name`='$host',`target`='$target',`target_ip`='$target_ip',`status`='$status' WHERE session='".$_SESSION['date_time']."'");
if($insert_all_data) {
echo "<script>alert('successfully');</script>";
} else {
echo "<script>alert('!!!!!not successfully');</script>";
}
}
}
}
}
?>
<form method="post" action="" >
<div class="tab-content">
<div class="tab-pane padding-20 active slide-left" id="tab1">
<div class="row row-same-height">
<div class="col-md-12">
<div class="padding-30">
<div class="row clearfix">
<div class="col-sm-3">
<div class="form-group form-group-default">
<label><font size="2">ENTER YOUR EMAIL <span class="glyphicon glyphicon-envelope"></span></font></label><br>
<textarea cols="43" rows="9" name="email_verify" style="border-color:white;border-width:thin;padding:4pt;" multiple/></textarea><br>
</div>
</div>
</div>
<div class="row clearfix">
<div class="col-sm-3">
<button type="submit" name="email_verify_btn" class="btn btn-lg btn-info" style="padding:11pt;width:200px;"/><span><b><font size="2">SUBMIT</font></b></span></button>
</div>
</div> <br><br>
<div class="row clearfix">
<div class="col-sm-12">
<table width="100%" class="table ">
<tr class="success">
<th>PRIMARY EMAIL <span class="glyphicon glyphicon-envelope"></span></th>
<th>HOST NAME</th>
<th>TARGET</th>
<th>TARGET IP</th>
<th>STATUS</th>
</tr>
<?php
$select = $connect->query("SELECT * from `email_verify_list` where session='".$_SESSION['date_time']."' order by id");
while($row = $select->fetch_assoc()) {
?>
<tr>
<td><?php echo $row['primary_email']; ?></td>
<td><?php echo $row['host_name']; ?></td>
<td><?php echo $row['target']; ?></td>
<td><?php echo $row['target_ip']; ?></td>
<td><?php echo $row['status']; ?></td>
</tr>
<?php } ?>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</form>

how can i use Ajax and Jquery to my code

i am very new to Ajax and jquery.
I have already post my queston here
How can i use ajax with javascript function
but not clear to me,so i have paste my all code.
i am using the following javascript function to get the value from the list those user selected from list and pass this value to sql query to display products.
i am trying to reaload only products.
but using this function each time the page is reloading. i am trying to use ajax using this function.how can i use ajax with this need syntax.
In this 3 things Reaload my whole page are 1)Search form 2)sort by 3)view on page(limit)
<?php
/*
Template Name:Wheel
*/
?>
<?php get_header(); ?>
<script type="text/javascript" language="javascript">
function pagelim(index){
var page_lim=$('#page_num li').get(index).id;
$("#main-content-wrap").load("<?php echo get_option('head'); ?>"+'?wheel&limit=' + page_lim);
}
</script>
<script type="text/javascript" language="javascript">
function dateby(index){
var date_by=$('#sort-by-date a').get(index).id;
var cls=document.getElementById(date_by).className;
if(date_by=="ASC")
{
date_by="DESC";
}
else
{
date_by="ASC";
}
self.location="<?php echo get_option('head'); ?>"+'?wheel&sort=' + date_by ;
}
</script>
<script type="text/javascript" language="javascript">
onLoad(){
//search-option_form.removeClass('jqtransformdone');
}
</script>
<?php
$sort_by=$_GET['sort'];
if($sort_by=="")
{
$sort_by="ASC";
}
else
{
$sort_by=="DESC";
}
$page = (get_query_var('page')) ? get_query_var('page') : 1;
$lim=$_GET['limit'];
if($lim=="")
$limit = 1;
else
$limit =$lim;
$offset = ( $page - 1 ) * $limit;
if(isset($_POST['searchsubmit']))
{
$i=1;
$search_query="SELECT * FROM wp_products WHERE 1";
if($_POST['rim_size']!=0)
{$search_query=$search_query." AND rim='".$_POST['rim_size']."'"." ";}
if($_POST['studs']!=0)
{$search_query=$search_query." AND studs='".$_POST['studs']."'"." ";}
if($_POST['miles']!=0)
{
$value=$_POST['miles']-5000;
$search_query=$search_query." AND miles BETWEEN $value AND ". $_POST['miles']." ";
}
if(($_POST['min_price']!=0)&&($_POST['max_price']!=0))
{
$search_query=$search_query." AND "."price BETWEEN ". $_POST['max_price']." AND ".$_POST['min_price']." ";
}
$search_query=$search_query." LIMIT $offset,$limit";
$data=$wpdb->get_results($search_query);
}//if ends
else{$data = $wpdb->get_results("select * from wp_products order by product_id $sort_by
LIMIT $offset,$limit ");}
?>
<div class="main noborder" >
<div id="main-content-wrap">
<!-- - - - - - - - - - - - - - - Container - - - - - - - - - - - - - -
- - -->
<section class="container sbr clearfix left-section">
<!-- - - - - - - - - - - - - - - Content - - - - - - - - - - - - - - -
- -->
//here is search box
<div class="widget_custom_search">
<h3 class="widget-title"><span>Search</span> Filters</h3>
<form method="post" id="search-option-form" class="form-panel">
<fieldset>
<label>Rim Size</label>
<select name="rim_size" class="width-190">
<option value="0" >Select</option>
<option value="15" <?php if($_POST['rim_size']=="15") { ?> selected="selected" <?php } ?>>15 Inch</option>
<option value="16" <?php if($_POST['rim_size']=="16") { ?> selected="selected" <?php } ?>>16 Inch</option>
<option value="17" <?php if($_POST['rim_size']=="17") { ?> selected="selected" <?php } ?>>17 Inch</option>
<option value="18" <?php if($_POST['rim_size']=="18") { ?> selected="selected" <?php } ?>>18 Inch</option>
<option value="19" <?php if($_POST['rim_size']=="19") { ?> selected="selected" <?php } ?>>19 Inch</option>
</select>
</fieldset>
<fieldset>
<label>No. of Studs</label>
<select name="studs" class="width-190">
<option value="0">Select</option>
<option value="3" <?php if($_POST['studs']=="3") { ?> selected="selected" <?php } ?> >3</option>
<option value="4" <?php if($_POST['studs']=="4") { ?> selected="selected" <?php } ?> >4</option>
</select>
</fieldset>
<fieldset>
<span class="w110p floatLeft display-block">
<label>Min Price</label>
<select name="min_price" class="floatLeft">
<option value="0">Select</option>
<option value="1000" <?php if($_POST['min_price']=="1000") { ?> selected="selected" <?php } ?> >1000</option>
<option value="2000" <?php if($_POST['min_price']=="2000") { ?> selected="selected" <?php } ?>>2000</option>
['min_price']=="6000") { ?> selected="selected" <?php } ?>>6000</option>
</select>
</span> <span class="w110p floatLeft display-block">
<label>Max Price</label>
<select name="max_price" class="floatLeft">
<option value="0">Select</option>
<option value="1000" <?php if($_POST['max_price']=="1000") { ?> selected="selected" <?php } ?>>1000</option>
<option value="2000" <?php if($_POST['max_price']=="2000") { ?> selected="selected" <?php } ?>>2000</option>
<option value="3000" <?php if($_POST['max_price']=="3000") { ?> selected="selected" <?php } ?>>3000</option>
</select>
</span>
</fieldset>
<fieldset>
<label>Miles</label>
<select name="miles" class="width-190">
<option value="0">Select</option>
<option value="5000" <?php if($_POST['miles']=="5000") { ?> selected="selected" <?php } ?>>5000</option>
<option value="10000" <?php if($_POST['miles']=="10000") { ?> selected="selected" <?php } ?>>10000</option>
<option value="60000" <?php if($_POST['miles']=="60000") { ?> selected="selected" <?php } ?>>60000</option>
<option value="65000" <?php if($_POST['miles']=="65000") { ?> selected="selected" <?php } ?>>65000</option>
<option value="70000" <?php if($_POST['miles']=="70000") { ?> selected="selected" <?php } ?>>70000</option>
</select>
</fieldset>
<fieldset class="top-padding-30">
<button name="searchsubmit" type="submit" id="searchsubmit" class="common-button green-button-bg w90p floaL mLeft5">SEARCH</button>
</fieldset>
</form>
<!--/ .form-panel-->
</div>
</section>
<!--/.container -->
<!-- - - - - - - - - - - - - end Container - - - - - - - - - - - - - -
- - -->
<section class="container clearfix right-section">
<div id="pagination-sort-lniks">
<?php
$total=$wpdb->get_results("select * from wp_products ");
$pages = COUNT($total);
$pages = ceil($pages / $limit);
$querystring = "";
foreach ($_GET as $key => $value) {
if ($key != "page") $querystring .= "$key=$value&";
}
// Pagination
?>
<?php if($sort_by=="ASC")
$class="up-arrow";
else
$class="down-arrow";
//here to select sort by and view on page ?>
<div class="sort-links"><span class="by-date" id="sort-by-date">Sort by: <a href="#" id='<?php _e($sort_by)?>' class='<?php _e($class)?>' onclick="dateby($(this).index())" >Date</a>
</span>
<span id="view-on-page">View on Page: <?php if($lim=="") { _e($limit); } else { _e($lim); } ?>
<ul id="page_num">
<li id="5" onclick="pagelim($(this).index())">5</li>
<li id="10" onclick="pagelim($(this).index())">10</li>
<li id="15" onclick="pagelim($(this).index())">15</li>
</ul>
</span>
</div>
<div class="pagination">
<?php
if( $pages > 1)
{
$range=1;
$showitems = ($range * 2)+1;
$page1=$page;
$prev=$page1-1;
if($page > 1)
{
echo "<a class=\"page gradient\" ";
echo "href=\"?{$querystring}page=$prev";
echo "\">Previous</a> ";
}
for ($i = 1; $i <= $pages; $i++)
{
if (1 != $pages &&( !($i >= $page+$range+1 || $i <= $page-$range-1) || $pages <= $showitems ))
{
if($i == $page)
{
echo "<span class=\" page active\">".$i."</span>";
}
else
{
echo "<a class=\"page gradient\"";
echo "href=\"?{$querystring}page=$i";
echo "\">$i</a> ";
}
}
}
if($page!=$pages)
{
if($showitems < $pages)
{
echo "..... ";
}
$page1=$page;
$next=$page1+1;
echo "<a " . ($i == $page ? "class=\"page active\" " : "class=\"page gradient\"");
echo "href=\"?{$querystring}page=$next";
echo "\">Next</a> ";
}
}
?>
</div>
</div>
<?php
$tim_path = get_bloginfo('template_directory')."/scripts/timthumb.php?src=";
if(count($data)>0)
{
foreach($data as $row)
{
$userid = $row->dealer_id;
$metakey="addr1";
$prod_id = $row->product_id;
$image=$wpdb->get_results("select DISTINCT(product_id),prod_image from wp_product_images where product_id=$prod_id LIMIT 1");
foreach($image as $row1)
{
$image_name = $row1->prod_image;
}
?>
<?php $location=get_usermeta( $userid, $metakey ); ?>
<ul class="product-wrap" id="product-wrap">
<li><a href="#" class="current details-link" ><img src="<?php _e($tim_path) ?><?php bloginfo('template_directory');?>/product_images/<?php _e($image_name."&w=140&h=105&zc=0&watermark=0") ?>" class="thumb" alt=""/>
<?php if($row->bestdeal==1)
{?>
<span class="best-deal-icon right100" ></span> <?php }?>
</a>
<div class="product-title clearfix">
<h3 class="textBold"><?php _e($row->product_name) ?></h3>
<span class="product-price bTextColor"><?php _e($row->price)?></span> </div>
<div class="tech-details"> <span class="span1">Technical details : </span> <span class="span2"><?php _e($row->rim) ?>"</span> <span
class="span3"><?php _e($row->studs) ?>Studs</span> <span class="span4"><?php _e($row->colour) ?></span>
<span class="span5"><?php _e($row->miles) ?>Mil</span> </div>
<div class="location-details" style=""> <span class="location-display">Location : <?php _e($location) ?> </span> <span
class="view-details">View details </span> </div>
</li>
</ul>
<?php }
}
else
{
echo '<div class="no_records">Sorry!!No Products Found You Can Search Another. </div>';
}
?>
<!--/ .adjective-->
<div id="pagination-sort-lniks">
<div class="pagination">
<?php
if( $pages > 1)
{
$range=1;
$showitems = ($range * 2)+1;
$page1=$page;
$prev=$page1-1;
if($page > 1)
{
echo "<a class=\"page gradient\" ";
echo "href=\"?{$querystring}page=$prev";
echo "\">Previous</a> ";
}
for ($i = 1; $i <= $pages; $i++)
{
if (1 != $pages &&( !($i >= $page+$range+1 || $i <= $page-$range-1) || $pages <= $showitems ))
{
if($i == $page)
{
echo "<span class=\" page active\">".$i."</span>";
}
else
{
echo "<a class=\"page gradient\"";
echo "href=\"?{$querystring}page=$i";
echo "\">$i</a> ";
}
}
}
if($page!=$pages)
{
if($showitems < $pages)
{
echo "..... ";
}
$page1=$page;
$next=$page1+1;
echo "<a " . ($i == $page ? "class=\"page active\" " : "class=\"page gradient\"");
echo "href=\"?{$querystring}page=$next";
echo "\">Next</a> ";
}
}
?>
</div>
</div>
</section>
</div>
</div>
<!--/ .main-->
<?php get_footer();?>
With Jquery/Ajax the execution flow is different, let me try to explain:
PHP is executed on the server, after the execution the result is pure HTML+CSS+javascript. This result is then send to the client, where the browser will display it.
So what you are doing here is calling the same PHP multiple times, and depending of the variables you pass to it you generate diferent HTML+CSS+javascript results.
So how would this work if we add Jquery/Ajax?
You would call your PHP once, the result generated HAS to contain the Jquery/Ajax code in the head tag. (you need the jquery JS file added as a script tag). When the user decides to do a sort you don't call the entire PHP script again. You should call a second PHP script, dedicated to only return the HTML part you want to refresh. Here's a example:
$.post("returnhtml.php", {var1: var1, var2: var2}, function(data){
// the var data contains everything "returnhtml.php" echoed
$("#div_we_want_to_refresh_id").html(data);
});
Hope this helped.

Categories