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

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>

Related

How to create Insert data via Excel upload which contains half of mysql table

my Controllers
public function uploadexcel()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'xlsx|xls';
$config['file_name'] = 'doc' . time();
$this->load->library('upload', $config);
if ($this->upload->do_upload('importexcel')) {
$file = $this->upload->data();
$reader = ReaderEntityFactory::createXLSXReader();
$reader->open('uploads/' . $file['file_name']);
foreach ($reader->getSheetIterator() as $sheet) {
$numRow = 1;
foreach ($sheet->getRowIterator() as $row) {
if ($numRow > 1) {
$datareceiving = array(
'lot_number' =>$this->m_receiving->joinMasterpartBarcode()."/" . $this->m_receiving->bln() . "/" . $this->m_receiving->tgl() . "/" . $this->m_receiving->getSerialNumber(),
'upload_id' => $this->m_receiving->get_no_upload_id(),
'number_part' => $row->getCellAtIndex(0),
'description' => $row->getCellAtIndex(1),
'shift' => $row->getCellAtIndex(2),
'date_production' => $row->getCellAtIndex(3),
'date_receive' => $row->getCellAtIndex(4),
'qty_transfer' => $row->getCellAtIndex(5),
'pic' => $row->getCellAtIndex(6),
'txndate' => $this->m_receiving->today(),
);
$this->m_receiving->import_data($datareceiving);
}
$numRow++;
}
$reader->close();
unlink('uploads/' . $file['file_name']);
$this->session->set_flashdata('success', 'Import Excel berhasil');
redirect('receiving');
}
} else {
echo "Error : " . $this->upload->display_errors();
}
}
public function exportexcel()
{
$get = $this->m_receiving->getAll();
// Validasi jumlah
$get->num_rows();
$writer = WriterEntityFactory::createXLSXWriter();
$writer->openToBrowser('Receiving.xlsx');
$header =
[
WriterEntityFactory::createCell('Part Number'),
WriterEntityFactory::createCell('Description'),
WriterEntityFactory::createCell('Shift'),
WriterEntityFactory::createCell('Date Production'),
WriterEntityFactory::createCell('Date Receive'),
WriterEntityFactory::createCell('Qty Transfer'),
WriterEntityFactory::createCell('Customer'),
WriterEntityFactory::createCell('PIC'),
WriterEntityFactory::createCell('Txndate'),
WriterEntityFactory::createCell('Userid'),
];
$singleRow = WriterEntityFactory::createROW($header);
$writer->addRow($singleRow);
$data = array();
// looping pembacaan Data
foreach ($get->result() as $key) {
$data_assetdata = array(
WriterEntityFactory::createCell($key->part_number),
WriterEntityFactory::createCell($key->description),
WriterEntityFactory::createCell($key->shift),
WriterEntityFactory::createCell($key->date_production),
WriterEntityFactory::createCell($key->date_receive),
WriterEntityFactory::createCell($key->qty_transfer),
WriterEntityFactory::createCell($key->id_customer),
WriterEntityFactory::createCell($key->pic),
WriterEntityFactory::createCell($key->txndate),
WriterEntityFactory::createCell($key->userid),
);
array_push($data, WriterEntityFactory::createRow($data_assetdata));
}
$writer->addRows($data);
$writer->close();
}
and this my Model
public function lihat()
{
$query = $this->db->get($this->_table);
return $query->result();
}
public function jumlah()
{
$query = $this->db->get($this->_table);
return $query->num_rows();
}
public function lihat_id($receive_id)
{
$query = $this->db->get_where($this->_table, ['receive_id' => $receive_id]);
return $query->row();
}
public function ubah($data, $receive_id)
{
$query = $this->db->set($data);
$query = $this->db->where(['receive_id' => $receive_id]);
$query = $this->db->update($this->_table);
return $query;
}
public function tambah($data)
{
return $this->db->insert($this->_table, $data);
}
public function hapus($receive_id)
{
return $this->db->delete($this->_table, ['receive_id' => $receive_id]);
}
public function getAll()
{
$this->db->from('receiving');
return $this->db->get();
}
function get_no_upload_id()
{
$q = $this->db->query("SELECT MAX(RIGHT(upload_id,2)) AS kd_max FROM receiving WHERE DATE(txndate)=CURDATE()");
$char = "-";
$kd = "";
if ($q->num_rows() > 0) {
foreach ($q->result() as $k) {
$tmp = ((int)$k->kd_max) + 1;
$kd = $char . sprintf("%02s", $tmp);
}
} else {
$kd = "1";
}
date_default_timezone_set('Asia/Jakarta');
return date('Ymd') . $kd;
}
function getSerialNumber()
{
$this->db->select('RIGHT(receiving.receive_id,5) as kode', false);
$this->db->order_by('receive_id', 'DESC');
$this->db->limit(1);
$query = $this->db->get('receiving');
if ($query->num_rows() <> 0) {
$data = $query->row();
$kode = intval($data->kode) + 1;
} else {
$kode = 1;
}
$kode_max = str_pad($kode, 4, "0", STR_PAD_LEFT);
$kode_jadi = $kode_max;
return $kode_jadi;
}
public function import_data($datareceiving)
{
$jumlah = count($datareceiving);
if ($jumlah > 0) {
// Replcae (namatable , Parameter variable upload)
$this->db->replace('receiving', $datareceiving);
}
}
public function today()
{
$today = date('ymd');
return $today;
}
public function tgl()
{
$tgl = date('d');
return $tgl;
}
public function bln()
{
$tgl = date('m');
return $tgl;
}
public function joinMasterpart()
{
$this->db->select('*');
$this->db->from('receiving');
$this->db->join('master_part', 'receiving.number_part = master_part.part_number','INNER');
$this->db->join('master_customer', 'master_part.id_customer = master_customer.id_customer','INNER');
$query = $this->db->get();
return $query->result();
}
public function joinMasterpartBarcode()
{
$this->db->select('*');
$this->db->from('receiving');
$this->db->join('master_part', 'receiving.number_part = master_part.part_number','INNER');
$this->db->join('master_customer', 'master_part.id_customer = master_customer.id_customer','INNER');
$query = $this->db->get();
return $query->result();
}
public function detail($part_number)
{
$this->db->select('*');
$this->db->from('receiving');
$this->db->join('master_part', 'receiving.number_part = master_part.part_number');
$this->db->where('part_number',$part_number);
$this->db->join('master_customer', 'master_part.id_customer = master_customer.id_customer');
$query = $this->db->get();
return $query->row();
}
and this my Html
<div id="wrapper">
<!-- load sidebar -->
<?php $this->load->view('partials/sidebar.php') ?>
<div id="content-wrapper" class="d-flex flex-column">
<div id="content" data-url="<?= base_url('incoming') ?>">
<!-- load Topbar -->
<?php $this->load->view('partials/topbar.php') ?>
<div class="container-fluid">
<div class="clearfix">
<div class="float-left">
<h1 class="h3 m-0 text-gray-800"><?= $title ?></h1>
</div>
<div class="float-right">
<i class="fa fa-file-excel"></i> Export Excel
<i class="fa fa-file-pdf"></i> Export Pdf
<i class="fa fa-plus"></i> Tambah
<button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#importdataketua">
<i class="fa fa-file-import"></i> Import
</button>
</div>
</div>
<hr>
<?php if ($this->session->flashdata('success')) : ?>
<div class="alert alert-success alert-dismissible fade show" role="alert">
<?= $this->session->flashdata('success') ?>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<?php elseif ($this->session->flashdata('error')) : ?>
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<?= $this->session->flashdata('error') ?>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<?php endif ?>
<div class="card shadow">
<div class="card-header"><strong>Receiving</strong></div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
<thead>
<tr>
<td>Lot Number</td>
<td>Upload Id</td>
<td>Part Number</td>
<td>Description</td>
<td>Shift</td>
<td>Date Production</td>
<td>Date Receive</td>
<td>Qty Transfer</td>
<td>Pic</td>
<td>Txndate</td>
<td>Id Customer</td>
<td>Customer Name</td>
<td>Action</td>
</tr>
</thead>
<tbody>
<?php $no = 1; ?>
<?php foreach ($all_receiving as $rows_allReceiving) { ?>
<tr>
<td>
<?= $rows_allReceiving->id_customer ?><?= $rows_allReceiving->lot_number ?>
<i class="fa fa-barcode"></i> Generate
</td>
<td><?= $rows_allReceiving->upload_id?></td>
<td>
<?= $rows_allReceiving->number_part?>
</td>
<td><?= $rows_allReceiving->description?></td>
<td><?= $rows_allReceiving->shift?></td>
<td><?= $rows_allReceiving->date_production ?></td>
<td><?= $rows_allReceiving->date_receive ?></td>
<td><?= $rows_allReceiving->qty_transfer ?></td>
<td><?= $rows_allReceiving->pic ?></td>
<td><?= $rows_allReceiving->txndate ?></td>
<td><?= $rows_allReceiving->id_customer ?></td>
<td><?= $rows_allReceiving->nama_customer ?></td>
<td>
<i class="far fa-folder"></i> Detail
<a onclick="return confirm('apakah anda yakin?')" href="<?= base_url('receiving/hapus/' . $rows_allReceiving->receive_id) ?>" class="btn btn-danger btn-sm"><i class="fa fa-trash"></i> Hapus</a>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<!-- load footer -->
<?php $this->load->view('partials/footer.php') ?>
</div>
</div>
<!-- Modal -->
<div class="modal fade" id="importdataketua" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Import Excel</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<?= form_open_multipart('receiving/uploadexcel') ?>
<div class="form-group">
<label for="exampleFormControlFile1">Upload File</label>
<input type="file" class="form-control-file" id="exampleFormControlFile1" name="importexcel">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary"><i class="fa fa-file-import"></i> Upload</button>
</div>
<?= form_close(); ?>
</div>
</div>
</div>
<?php $this->load->view('partials/js.php') ?>
<script src="<?= base_url('sb-admin/js/demo/datatables-demo.js') ?>"></script>
<script src="<?= base_url('sb-admin') ?>/vendor/datatables/jquery.dataTables.min.js"></script>
<script src="<?= base_url('sb-admin') ?>/vendor/datatables/dataTables.bootstrap4.min.js"></script>
<script>
function autofill() {
$.ajax({
url: 'receiving/autofillAjax',
data: 'part_number' + part_number,
}).success(function(data) {
alert('masuk');
});
}
</script>
HELP
am stuck here. I have a project that makes a table receiving with the added method using an import file with Xlsx extension ( Excel ) , they have 21 column inside table mysql and user just import file in a part. and I want it when the upload is successful. All empty data in the table is quickly filled by retrieving data from another table such as vlookup. am using Codeigniter 3.

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

delete image ins database mysql from dashboard php

hi i need help i have problem in my code and i can't figure the solutions please help me .
this is the dashboard:
image dashboard
and this is problem after click on delete:
delete problem
and this is my code php of posts file:
<?php
/*
===========================================================
=== Manage Members Page ===
=== You can add | edit | delete Members from here ===
===========================================================
*/
session_start();
if (isset($_SESSION['Username'])) {
include 'init.php';
$pageTitle = 'Posts';
$do = isset($_GET['do']) ? $_GET['do'] : 'Manage' ;
//Start Manage Page
if ($do == 'Manage'){ // Manage Members Page
$sort = 'ASC';
$sort_arry = array('ASC', 'DESC');
if(isset($_GET['sort']) && in_array($_GET['sort'], $sort_arry)) {
$sort = $_GET['sort'];
}
$stmt2 = $con->prepare("SELECT * FROM posts ORDER BY Ordering $sort");
$stmt2->execute();
$rows = $stmt2->fetchAll();
?>
<h1 class="text-center"> Manage Posts </h1>
<div class="container categories">
<div class="panel panel-default">
<div class="panel-heading">
<i class="fa fa-edit"></i> Manage Posts
<div class="ordering pull-right">
<i class="fa fa-sort"> </i>Ordering: [
<a class="<?php if ($sort == 'ASC') { echo 'active'; } ?>" href="?sort=ASC">Asc </a> |
<a class="<?php if ($sort == 'DESC') { echo 'active'; } ?>" href="?sort=DESC">Desc </a>
]
</div>
</div>
<div class="row">
<?php
foreach ($rows as $image) {
echo '<div class="col-md-3 col-sm-4 "><div class="thumbnail">';
echo '<h2 class="h4">'.$image['Name']. '</h2><div class="main">';
echo '<img src="data:image;base64,'.$image['Image'].' " alt="image name" title="image title" width="255" heigth="255">';
echo '</div>';
echo '<table class="table table-bordered">';
echo '<tr>';
echo '<td>' . "<a href='posts.php?do=Edit&id=". $image['ID'] ."' class='btn btn-xs btn-primary'><i class='fa fa-edit'></i> edit</a>" . '</td>';
echo '<td>' . "<a href='posts.php?do=Delete&id=". $image['ID'] ."' class='btn btn-xs btn-danger'><i class='fa fa-close'></i> Delete</a>" . '</td>';
echo '</tr>';
echo '</table>';
echo '</div>';
echo '</div>';
}
?>
</div>
<?php } elseif ($do == 'Add') { //add Member page ?>
<h1 class="text-center"> ajouter un nouveau post </h1>
<div class="container">
<form class="form-horizontal" enctype="multipart/form-data" action="?do=Insert" method="POST">
<!-- start Username fieled -->
<div class="form-group">
<label class="col-sm-2 control-label">Titre</label>
<div class="col-sm-10 col-md-8">
<input type="text" name="image-name" class="form-control" autocomplete="off" placeholder="username pour se connecter dans le site Web" required />
</div>
</div>
<!-- end Username fieled -->
<!-- start Password fieled -->
<div class="form-group">
<label class="col-sm-2 control-label">Image</label>
<div class="col-sm-10 col-md-8">
<input type="file" name="image" class="form-control" placeholder="mot de passe doit être difficile et complexe" required/>
</div>
</div>
<!-- end Password fieled -->
<!-- start Full name fieled -->
<div class="form-group">
<label class="col-sm-2" for="categorie">Categories:</label>
<div class="col-sm-10 col-md-8">
<select class="form-control" name="categorie">
<?php
$stmt = $con->prepare("SELECT * FROM `categories`");
// Execute the Statments
$stmt->execute();
// Assign to variable
$rows = $stmt->fetchAll();
?>
<?php
foreach ($rows as $cat) {
echo "<option value='" . $cat['ID'] . "'>". $cat['Name'] . "</option>";
}
?>
</select>
</div>
</div>
<!-- end Full name fieled -->
<!-- start submit fieled -->
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<input type="submit" value="Ajouter" class="btn btn-primary" />
</div>
</div>
<!-- end submit fieled -->
</form>
</div>
<?php
} elseif ($do == 'Insert') {
//insert Members Page
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
echo "<h1 class='text-center'> insert an post </h1>";
echo "<div class='container'>";
// Get variable from the form
$name = $_POST['image-name'];
$image= addslashes($_FILES['image']['tmp_name']);
$image= file_get_contents($image);
$image= base64_encode($image);
$cat = $_POST['categorie'];
//validate the form
$formErrors = array();
if (strlen($name) < 4) {
$formErrors[] = "title name cant be less then <strong> 4 caracter</strong>";
}
if (strlen($name) > 20) {
$formErrors[] = "title name cant be More then <strong> 20 caracter</strong>";
}
if (empty($name)) {
$formErrors[] = "Username Cant Be <strong>Empty</strong>";
}
// loop into eroos array and echo it
foreach ($formErrors as $Error) {
echo "<div class='alert alert-danger'>" . $Error . "</div>";
}
// check if There is no error procced the operations
if (empty($formErrors)) {
// check if user exist in database
$check = checkItem("Username", "users", $user);
if ($check == 1) {
$theMsg = "<div class='alert alert-danger'> Sorry this user is exist </div>";
redirectHome($theMsg, 'back');
} else {
// Insert User info into database
$stmt = $con->prepare("INSERT INTO posts(Name, Image, Cat_id)
VALUES (:name, :image, :cat)");
$stmt->execute(array(
'name' => $name,
'image' => $image,
'cat' => $cat,
));
// echo success message
$theMsg = "<div class='alert alert-success'>" . $stmt->rowCount() . ' Record Inserted </div> ';
redirectHome($theMsg, 'back', 5);
}
}
} else {
echo "<div class='container'>";
$theMsg = '<div class="alert alert-danger"> Sorry you cant browse this page directely </div>';
redirectHome($theMsg, 'back', 5); // 6 is secend of redirect to page in function
echo "</div>";
}
echo "</div>";
} elseif ($do == 'Edit') { // Edit Page
//check if GET request userid Is numeric & Get The integer value of it
$post = isset($_GET['id']) && is_numeric($_GET['id']) ? intval($_GET['id']) : 0;
//sellect All Data Depend On This ID
$stmt = $con->prepare("SELECT * FROM posts WHERE ID = ? LIMIT 1");
// execute Query
$stmt->execute(array($post));
//fetch the Data
$row = $stmt->fetch();
// The row count
$count = $stmt->rowCount();
// If Ther's Such Id show The Form
if ($count > 0) { ?>
<h1 class="text-center"> Modifier Post </h1>
<div class="container">
<form class="form-horizontal" enctype="multipart/form-data" action="?do=Update" method="POST">
<div class="col-md-6 col-md-offset-3 panel">
<input type="hidden" name="id" value="<?php echo $_GET['id']; ?>
<!-- start title fieled -->
<div class="form-group">
<label class="col-sm-2 control-label">Titre</label>
<div class="col-sm-10 col-md-8">
<input type="text" name="name" class="form-control" autocomplete="off" required value="<?php echo $row['Name']; ?>" >
</div>
</div>
<!-- end title field -->
<!-- start image filed -->
<div class="form-group">
<label class="col-sm-2 control-label">image</label>
<div class="col-sm-10 col-md-8">
<input type="file" name="image" class="form-control" />
</div>
</div>
<!-- end image filed -->
<!-- start Categories filed -->
<div class="form-group">
<label class="col-sm-2" for="categorie">Categories:</label>
<div class="col-sm-10 col-md-8">
<select class="form-control" name="categorie">
<?php
$stmt = $con->prepare("SELECT * FROM `categories`");
// Execute the Statments
$stmt->execute();
// Assign to variable
$rows = $stmt->fetchAll();
?>
<?php
foreach ($rows as $cat) {
echo "<option value='" . $cat['ID'] . "'>". $cat['Name'] . "</option>";
}
?>
</select>
</div>
</div>
<!-- Categories end-->
<!-- start submit fieled -->
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<input type="submit" value="sauvegarder" class="btn btn-primary" />
</div>
</div>
<!-- end submit fieled -->
</div>
</form>
</div>
<?php
// if there's No Such id Show Error Message
} else {
echo "<div class='container'>";
$theMsg = "<div class='alert alert-danger'>Theres is no such Id</div>";
redirectHome($theMsg);
echo "</div>";
}
} elseif ($do == 'Update') {
echo "<h1 class='text-center'> mis a jour Membre </h1>";
echo "<div class='container'>";
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// Get variable from the form
$id = $_POST['id'];
$name = $_POST['name'];
$image = addslashes($_FILES['image']['tmp_name']);
$image = file_get_contents($image);
$image = base64_encode($image);
$cat = $_POST['categorie'];
//validate the form
$formErrors = array();
if (empty($name)) {
$formErrors[] = "<div class='alert alert-danger'>Username Cant Be <strong>Empty</strong> </div>";
}
if (empty($image)) {
$formErrors[] = "<div class='alert alert-danger'>FullName Cant Be <strong>Empty</strong></div>";
}
if (empty($cat)) {
$formErrors[] = "<div class='alert alert-danger'>Email Cant Be <strong>Empty</strong></div>";
}
// loop into eroos array and echo it
foreach ($formErrors as $Error) {
echo $Error;
}
// check if There is no error procced the operations
if (empty($formErrors)) {
// Update The Database With This Info
$stmt = $con->prepare("UPDATE posts SET Name = ? , Image = ? , Cat_id = ? WHERE ID = ?");
$stmt->execute(array($name, $image, $cat, $id));
// echo success message
$theMsg = "<div class='alert alert-success'>" . $stmt->rowCount() . ' Record Updated </div> ';
redirectHome($theMsg, 'back');
}
} else {
$theMsg = '<div class="alert alert-danger">Sorry you cant browse this page directely </div>';
redirectHome($theMsg);
}
echo "</div>";
}
elseif ($do == 'Delete') { // Delete Member Page
echo "<h1 class='text-center'> Delete Membre </h1>";
echo "<div class='container'>";
//check if GET request userid Is numeric & Get The integer value of it
$id = isset($_GET['id']) && is_numeric($_GET['id']) ? intval($_GET['id']) : 0;
//sellect All Data Depend On This ID
$check = checkItem('id', 'posts', $id);
// If Ther's Such Id show The Form
if ($check > 0) {
$stmt = $con->prepare("DELETE FROM users WHERE ID = :id");
$stmt->bindParam(":id", $id);
$stmt->execute();
$theMsg = "<div class='alert alert-success'>" . $stmt->rowCount() . ' Record Deleted </div> ';
redirectHome($theMsg);
} else {
$theMsg = "<div class='alert alert-danger'>This id not exist</div>";
redirectHome($theMsg);
}
echo "</div>";
}
include $tpl . 'footer.php';
} else {
header('Location: index.php') ;
exit();
}
from the error, id is the problem.
isset($_GET['id']) && is_numeric($_GET['id'])
i think what u want is
(isset($_GET['id']) && is_numeric($_GET['id']) )//close parantheses in wrong position

showing an alert message after submit

I'm having a problem showing an alert message after submitting a form.
I have a form for submitting a report, then after submission it will be stored in a table. What I want to happen is that after submitting a report, there will be an alert message for each new submitted report. I'm using CI as framework. Here is what I have:
View:
<div class="row-fluid">
<button type="button" class="btn btn-primary col-lg-2" data-toggle="collapse" data-target="#add_form" onclick="add_clicked()">Submit Report</button><br />
<div class="col-lg-6">
<?php
$attributes = array('class' => $class, 'id' => 'add_form', 'role' => 'form');
echo form_open('admin/report', $attributes);?>
<div class="form-group">
<input class="form-control" type="hidden" name="add_hidden" value="add-report">
</div>
<br><br>
<div class="form-group">
<?=form_input( array('id'=>'sender','class'=>'form-control' ,'name'=>'sender','type'=>'text','placeholder'=> 'Senders Name', 'value' => set_value('sender'), 'required'=> 'true') );?> <br />
<?=form_input( array('id'=>'date','class'=>'form-control date-picker','name'=>'date','type'=>'text','placeholder'=> 'Date', 'value' => set_value('date') ) );
$date = date('Y-m-d H:i:s');?><br />
<?=form_textarea( array('id'=>'subject','class'=>'form-control','name'=>'subject','type'=>'message-text','placeholder'=> 'Your Message here', 'value' => set_value('subject'), 'required'=> 'true') );?><br />
</div>
<div class="form-group">
<?=form_input( array('class'=>'btn btn-success','id'=>'add_submit','type'=>'submit','value'=>'submit')) ;?>
</div>
<?=form_close();?>
</div>
<div class="col-md-10 text-center" id="success" style="display:none">
<?php if(isset($message)) echo $message ?>
</div>
</div>
</div>
<br> <br>
<div class="table-responsive">
<table class="table table-hover table-striped">
<thead>
<tr>
<th style="text-align: center">Sender</th>
<th style="text-align:center">Subject</th>
<th style="text-align:center">Date</th>
</tr>
</thead>
<tbody>
<?php
foreach ($query->result_array() as $row) {
echo '
<tr>
<td style="text-align:center">'.$row["sender"].'</td>
<td style="text-align:center">'.$row["subject"].'</td>
<td style="text-align:center">'.$row["date"].'</td>
<td> <button type="button" class="btn btn-success btn-small" data-toggle="modal" data-target="#view'.$row["sender"].'"> Read </button>
<button type="button" class="btn btn-danger btn-small" data-toggle="modal" data-target="#remove'.$row["sender"].'">delete</button></td>
</tr>
';
}
?>
This is my controller:
public function report()
{
$this->load->model('report_model', 'database');
$sql = "SELECT * FROM report";
$data['query'] = $this->database->view_report($sql);
if ($this->input->post('add_hidden')) {
$this->form_validation->set_rules('sender', 'sender', 'required');
$this->form_validation->set_rules('subject', 'subject', 'required');
$this->form_validation->set_rules('date', 'date');
$this->form_validation->set_error_delimiters('<div class="has-error" style="color: #FF0000">', '</div>');
if ($this->form_validation->run() == TRUE) {
//Setting values for table columns
$data = array(
'sender' => $this->input->post('sender'),
'subject' => $this->input->post('subject'),
'date' => $this->input->post('date'),
);
//Transfering data to Model
$q = $this->database->add_report($data);
$data['query'] = $this->database->view_report($sql);
if ($q) {
$data['message'] = '<h3> Your report has successfully submitted!</h3>';
$data['success'] = '';
$data['class'] = 'collapse';
$this->load->view('report_view', $data);
} else {
$data['message'] = '<h3> Report submission unsuccessful!</h3>';
$data['success'] = '';
$data['class'] = 'collapse';
$this->load->view('report_view', $data);
}
}
else {
$data['message'] = '';
$data['success'] = 'none';
$data['class'] = '';
$this->load->view('report_view', $data);
}
}
else if ($this->input->post('del_hidden')) {
$from = $this->input->post('del_sender');
$subject = $this->input->post('del_subject');
$date = $this->input->post('del_date');
$qry = "DELETE FROM report WHERE sender = '$from'";
$q = $this->database->delete_report($qry);
$sql = "SELECT * FROM report";
$data['query'] = $this->database->view_report($sql);
if ($q) {
$data['message'] = '<h3> "' . $subject . '"message deleted from database!!</h3>';
$data['success'] = '';
$data['class'] = 'collapse';
$this->load->view('report_view', $data);
}
} else {
$data['success'] = 'none';
$data['class'] = 'collapse';
$this->load->view('report_view', $data);
}
}`
Actually you are displaying the message in view ; this part of your code is sufficient for that.
<div class="col-md-10 text-center" id="success" style="display:none">
<?php if(isset($message)) echo $message ?>
</div>
But the div has style display:none so it will not be displayed. So change it to
<?php if(isset($message))
{
?>
<div class="col-md-10 text-center" id="success">
<?php echo $message ?>
</div>
<?php
}
?>
if you want an alert message then you can change it to
<?php if(isset($message))
{
?>
<script>
alert('<?php echo $message ?>');
</script>
<?php
}
?>
If it is an javascript alert, search for the alert expression with the alerted message, put an . And use console.log()...

Categories