Data not inserting in the database using a modal - php

I am trying to update the status of my order using a modal. it doesnt shows any error but it does not update the status of the order in the database I already look at the form and my file is right. but i dont know why it does not update the status in my database.
here is the image where i update the order status it exec
`<!-- Transaction History -->
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span></button>
<h4 class="modal-title"><b>Transaction Full Details</b></h4>
</div>
<div class="modal-body">
<p>
Date: <span id="date"></span>
<span class="pull-right">Transaction#: <span id="transid"></span></span>
</p>
<table class="table table-bordered">
<thead>
<th>Product</th>
<th>Price</th>
<th>Quantity</th>
<th>Subtotal</th>
<th>Status</th>
</thead>
<tbody id="detail">
<tr>
<td colspan="4" align="right"><b>Total</b></td>
<td><span id="total"></span></td>
</tr>
<form action="order_edit.php" method="POST" enctype="multipart/form-data">
<td colspan="3" align="right"><b>Status</b></td>
<td><span id="total">
<select name="status" id="status" class="form-control form-control-sm rounded-0" required>
<option value="1" <?php echo isset($meta['status']) && $meta['status'] == 1 ? 'selected' : '' ?>>Pending</option>
<option value="3" <?php echo isset($meta['status']) && $meta['status'] == 3 ? 'selected' : '' ?>>Out for Delivery</option>
<option value="4" <?php echo isset($meta['status']) && $meta['status'] == 4 ? 'selected' : '' ?>>Done and Paid</option>
</select>
</span></td>
<td>
<button type="submit" class="btn btn-success btn-flat" name="edit"><i class="fa fa-check-square-o"></i> Update</button>
</td>
</form>
</tbody>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default btn-flat pull-left" data-dismiss="modal"><i class="fa fa-close"></i> Close</button>
</div>
</div>
</div>
`
`<?php
include 'includes/session.php';
if(isset($_POST['edit'])){
$id = $_POST['id'];
$status = $_POST['status'];
date_default_timezone_set("Asia/Manila");
$date = date('Y-m-d h:i:sa');
$date1 = date('Y-m-d h:i:sa');
try{
$stmt = $conn->prepare("SELECT * FROM sales WHERE id=:id");
$stmt->execute(['id'=>$id]);
$row = $stmt->fetch();
$stmt = $conn->prepare("UPDATE sales SET dateDelivered=:dateDelivered, order_received=:order_received, status=:status WHERE id=:id");
$stmt->execute(['dateDelivered'=>$date,'order_received'=>$date1,'status'=>$status, 'id'=>$id]);
$_SESSION['success'] = 'Status updated successfully';
}
catch(PDOException $e){
$_SESSION['error'] = $e->getMessage();
}
$pdo->close();
}
else{
$_SESSION['error'] = 'Fill up Update Status form first';
}
header('location: sales.php');
?>`

Add the hidden input tag in form tag
<input type="hidden" name="id" value="<?php echo $meta['id']; ?>">

Related

PHP Ajax Update MySQL Data Through Bootstrap Modal

I want to update my database using php ajax modal. When updating the relevant field { $('#main_id').val(data.id); } don't pass an id to the update query therefor an insertion occurs without executing the updating query.
console log details when trying to update
I tried to solve this but I couldn't. without updating the existing data it inserts a new record
here is my index.php
<?php
$connect = mysqli_connect("localhost", "root", "", "ohmsp");
$query = "SELECT * FROM tbl_main_category ORDER BY cat_Id DESC";
$result = mysqli_query($connect, $query);
?>
<div id="employee_table">
<table class="table table-bordered">
<tr> <th width="70%">Employee id</th>
<th width="70%">Employee Name</th>
<th width="15%">Edit</th>
<th width="15%">View</th>
</tr>
<?php
while($row = mysqli_fetch_array($result))
{
?>
<tr> <td><?php echo $row["cat_Id"]; ?></td>
<td><?php echo $row["category_name"]; ?></td>
<td><input type="button" name="edit" value="Edit" id="<?php echo $row["cat_Id"]; ?>" class="btn btn-info btn-xs edit_data" /></td>
<td><input type="button" name="view" value="view" id="<?php echo $row["cat_Id"]; ?>" class="btn btn-info btn-xs view_data" /></td>
</tr>
<?php
}
?>
</table>
</div>
</div>
</div>
</body>
</html>
<div id="dataModal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Employee Details</h4>
</div>
<div class="modal-body" id="employee_detail">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div id="add_data_Modal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">PHP Ajax Update MySQL Data Through Bootstrap Modal</h4>
</div>
<div class="modal-body">
<form method="post" id="insert_form">
<label>Enter Employee Name</label>
<input type="text" name="category_name" id="category_name" class="form-control" />
<br />
<input type="hidden" name="main_id" id="main_id" />
<input type="submit" name="insert" id="insert" value="Insert" class="btn btn-success" />
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function(){
$('#add').click(function(){
$('#insert').val("Insert");
$('#insert_form')[0].reset();
});
$(document).on('click', '.edit_data', function(){
console.log('test')
var main_id = $(this).attr("id");
console.log(main_id)
$.ajax({
url:"fetch.php",
method:"POST",
data:{main_id:main_id},
dataType:"json",
success:function(data){
console.log(data)
$('#category_name').val(data.category_name);
console.log(data.category_name)
$('#main_id').val(data.id);
console.log(data.id)
$('#insert').val("Update");
$('#add_data_Modal').modal('show');
}
});
});
insert.php
<?php
$connect = mysqli_connect("localhost", "root", "", "ohmsp");
if(!empty($_POST))
{
$output = '';
$message = '';
$category_name = mysqli_real_escape_string($connect, $_POST["category_name"]);
if($_POST["main_id"] != '')
{
$query = "
UPDATE tbl_main_category
SET category_name='$category_name' WHERE cat_Id='".$_POST["main_id"]."'";
$message = 'Data Updated';
}
else
{
$query = "
INSERT INTO tbl_main_category(category_name)
VALUES('$category_name');
";
$message = 'Data Inserted';
}
fetch.php
<?php
//fetch.php
$connect = mysqli_connect("localhost", "root", "", "ohmsp");
if(isset($_POST["main_id"]))
{
$query = "SELECT * FROM tbl_main_category WHERE cat_Id = '".$_POST["main_id"]."'";
$result = mysqli_query($connect, $query);
$row = mysqli_fetch_array($result);
echo json_encode($row);
}
?>
You have Fetched the value from $('#main_id').val(data.id) instead of $('#main_id').val(data.cat_Id);
You have fetched value of id instead of cat_Id

PHP move A variable to another document

Hello so I am having a slight problem at the moment Basically I have a while loop that outputs a table called job from database along with a bid button that links to bid.php. When the button takes me to the page I want it to carry over the jobid of the row that the button was clicked so I can enter the specific value into my database does anyone have any ideas on how to move over currently I am trying to do it using POST but I keep getting errors and the variable dosnt seem to be moving over.I just get a blank page and the id is not displayed.
Here is findjob22.php:
<?php
require 'config.php';
if(isset($_POST['submit']))
{
$valueToSearch = $_POST['valueToSearch'];
// search in all table columns
// using concat mysql function
$query = "SELECT * FROM `job` WHERE CONCAT(`job_id`,`location`, `description`, `budget`, `duedate`,`title`) LIKE '%".$valueToSearch."%'";
$search_result = filterTable($query);
}
else {
$query = "SELECT * FROM `job`";
$search_result = filterTable($query);
}
// function to connect and execute the query
function filterTable($query)
{
$conn = mysqli_connect("localhost", "root", "", "bid4myjob");
$filter_Result = mysqli_query($conn, $query);
return $filter_Result;
}
?>
<!DOCTYPE html>
<html lang="en">
<!-- PAGE CONTENT -->
<div class="page-content page-search-result">
<div class="container">
<!-- Search Form -->
<form class="form form-horizontal" action="bid.php" method="post">
<div class="input-group input-group-lg">
<div class="input-group-btn">
<!--<select id="search-type-select" name="valueToSearch" class="multiselect multiselect-single-lg search-type-select">
<option value="all" selected="selected">All</option>
<option value="page">Page</option>
<option value="task">Task</option>
<option value="user">User</option>
<option value="image">Image</option>
</select>
</div>-->
<input class="form-control input-lg" type="text" name="valueToSearch" placeholder="type keyword ..." />
<span class="input-group-btn">
<button type="submit" name= "submit" value="Search" class="btn btn-primary btn-lg"><i class="icon ion-android-search"></i> Go</button>
</span>
</div>
</form>
<!-- End Search Form -->
</div>
</div>
<div>
<table>
<tr>
<th>id</th>
<th>Title</th>
<th>Location</th>
<th>Description</th>
<th>Budget</th>
<th>Due date</th>
</tr>
<!-- populate table from mysql database -->
<?php while($row = mysqli_fetch_array($search_result)):?>
<tr>
<?php //$jid= $row['job_id']; ?>
<td><?php echo $row['job_id']; ?></td>
<td><?php echo $row['title'];?></td>
<td><?php echo $row['location'];?></td>
<td><?php echo $row['description'];?></td>
<td><?php echo $row['price'];?></td>
<td><?php echo $row['duedate'];?></td>
<td><form method="post" action="bid.php" class="form-horizontal">
<?php //echo _("Enter ") . ' ' . $last_bid_plus . ' ' . _('or more'); ?>
<!--<div class="input-group ">
<input type="number" value="bid" class="form-control" name="bid" id= "bid" required/>
</div>
<br/>-->
<input type="submit" name="job_id" value="<?php $row['job_id']; ?>"
class="btn btn-xlarge btn-block btn-primary">bid</input>
<br/>
</form></td>
</tr>
<?php endwhile;?>
</table>
</div>
<!-- END PAGE CONTENT -->
</body>
</html>
Here is bid.php where I am trying to get the specific id of the row from findjob22.php:
<?php
// include "job.php"
$jobid = $_POST['job_id'];
echo "$jobid"
?>
<!--<html>
<div class="col-xs-8">
<div class="page-header white-content">
<h1><?= _('Your Bid') ?>.</h1>
</div>
<div class="white-content">
<div class="well">
<br/><br/>
<form method="post" action="/listings/bid/<?//=$listingID; ?>/confirm" class="form-horizontal">
<input type="hidden" value="<?=//$bid_amount?>" class="input-medium" name="bid_amount"/>
<input type="submit" name="sb_bid" value="<?php// echo _('I agree and I confirm my BID'); ?>" class="btn btn-medium btn-green" />
</form>
</div>
</div>
</div>
</html>-->
I am not sure you can pass values in the submit button, but you can use a hidden input to pass the value.
<input type="hidden" value="<?php echo $row['job_id']; ?>" name="job_id" />
<input type="submit" class="btn btn-xlarge btn-block btn-primary">bid</input>
If you want it to work like you have it use a button.
<button type="submit"
name="job_id"
value="<?php echo $row['job_id']; ?>"
class="btn btn-xlarge btn-block btn-primary">
bid
</button>
if you want to also pass some data:
<form method="post"
action="bid.php"
class="form-horizontal">
<div class="input-group">
<input type="text"
class="form-control"
name="bid"
id="bid" required />
</div>
<button type="submit"
name="job_id"
value="<?php echo $row['job_id']; ?>"
class="btn btn-xlarge btn-block btn-primary">
bid
</button>
<br/>
</form>
Then you will have a $_POST["job_id"] and $_POST["bid"] in bid.php

Using radio buttons to show approved or unapproved users in admin panel in php mysql

I have a project wherein I need to show unapproved and approved user from the database. I have to show it by radio buttons such as All, Approved and Unapproved. I want to know how to list each of them ,as the radio choice is clicked, on the same page. I am a fresher in PHP and its my first project and so highly confused.
I am trying to put in switch for radio and no idea about how to write MySQL query in each switch case. Is there any solution or code available? Is there any way to solve this?
Here is my code:
<?php include 'blocks/headerInc.php' ; ?>
<?php
$errmsg = "" ;
$module_id = '';
$query = '';
$date_from = '';
$date_to = '';
//Search section start here
$sqlQuery = "SELECT * FROM tbl_user WHERE type =3 " ;
if(isset($_REQUEST['submit']))
{
if(!empty($_REQUEST['date_from']))
{
$date_from = date("Y-m-d", strtotime($_REQUEST['date_from'])) ;
}
if(!empty($_REQUEST['date_to']))
{
$date_to = date("Y-m-d", strtotime($_REQUEST['date_to'])) ;
}
if(!empty($date_to) && empty($date_from))
{
$errmsg = "Please select valid date range.";
}
if(!empty($date_to) && (strtotime($date_from)> strtotime($date_to)))
{
$errmsg = "Please select valid date range.";
}
if($errmsg =='')
{
if(!empty($date_to) && (strtotime($date_from)<= strtotime($date_to)))
{
$sqlQuery .= " AND created_on BETWEEN '$date_from' AND '$date_to'";
}
$sqlQuery .= " order by id DESC";
}
$date_from = date("m/d/Y",strtotime($date_from));
$date_to = date("m/d/Y",strtotime($date_to));
$date_from = $date_from != '01/01/1970' ? $date_from : '';
$date_to = $date_to != '01/01/1970' ? $date_to : '';
}
?>
<div class="container pagecontainer">
<!-- Static navbar -->
<div class="row row-offcanvas row-offcanvas-right">
<!--/.col-xs-12.col-sm-9-->
<div class="col-sm-3 col-md-3 sidebar" id="sidebar">
<div id="left_panel" class="clearfix left">
<?php include 'blocks/leftnavInc.php' ; ?>
</div>
</div>
<div class="col-xs-12 col-sm-9 page-right">
<div class="panel panel-primary">
<div class="panel-heading">Search Registered Candidate</div>
<div class="panel-body">
<div class="column col-sm-offset-0">
<?php
if($errmsg!="")
{
echo "<div class='error'>".ucwords($errmsg)."</div>";
}
?>
<form class="form-horizontal" method="get" action="">
<div class="form-group">
<div class="col-md-6">
<div class="col-md-4">
<label for="username" class="control-label">Date From:</label>
</div>
<div class="col-md-8">
<div class="input-group date">
<input class="form-control datepicker" data-val="true" data-val-date="The field Dob must be a date." data-val-required="The Dob field is required." id="Dob" name="date_from" placeholder="Date From" type="text" value="<?php echo $date_from ; ?>" >
</div>
</div>
</div>
<div class="col-md-6">
<div class="col-md-4">
<label for="username" class="control-label">Date To:</label>
</div>
<div class="col-md-8">
<div class="input-group date">
<input class="form-control datepicker" data-val="true" data-val-date="The field Dob must be a date." data-val-required="The Dob field is required." id="Dob" name="date_to" placeholder="Date To" type="text" value="<?php echo $date_to ; ?>" >
</div>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-6">
<div class="col-md-8 text-left">
<button type="submit" name="submit" value="submit" class="btn btn-success"><i class="glyphicon glyphicon-floppy-disk"></i> Search</button>
<button type="reset" onClick="javascript:window.location.href='reportRegisteredUsers.php'" class="btn btn-danger"><i class="glyphicon glyphicon-ban-circle"></i> Cancel</button>
</div>
</div>
<div class="col-md-6">
<div class="col-md-4">
<label for="username" class="control-label"> </label>
</div>
<div class="col-md-8 text-right">
</div>
</div>
</div>
</form>
</div>
</div>
</div>
<div class="panel panel-primary">
<div class="panel-heading">Report:Candidate Reports</div>
<div class="panel-body">
<input type="radio" name="gender" value="male" checked="checked"> All Candidates<br>
<input type="radio" name="gender" value="female"> Approved Candidates<br>
<input type="radio" name="gender" value="other"> Unapproved Candidates<br>
<div class="column col-sm-offset-0">
<table id="example" class="table table-striped table-hover table-bordered dataTableReport dt-responsive nowrap" cellspacing="0" width="100%">
<thead>
<tr>
<th>S.No.</th>
<th>Email ID</th>
<th>SBI Employee ID</th>
<th>Name</th>
<th>Mobile No.</th>
<th>Date of Birth</th>
<th>Registration Date</th>
</tr>
</thead>
<tbody>
<?php
$sq = $db->query($sqlQuery);
$i = 1 ;
if($db->affected_rows > 0)
{
while($row=mysql_fetch_array($sq))
{
extract($row);
?>
<tr>
<td><?php echo $i ; ?></td>
<td><?php echo $email ; ?></td>
<td><?php echo $employee_id ; ?></td>
<td><?php echo $first_name." ".$middle_name." ".$last_name ; ?></td>
<td><?php echo $mobile ; ?></td>
<td><?php if($dob !='1970-01-01'){echo date("d-m-Y", strtotime($dob)) ; }?></td>
<td><?php echo date("d-m-Y", strtotime($created_on)) ; ?></td>
</tr>
<?php $i++;}} ?>
</tbody>
</table>
</div>
</div>
</div>
<div> <button type="reset" onClick="javascript:history.go(-1)" class="btn btn-danger"><i class="glyphicon glyphicon-ban-circle"></i> Go Back</button> </div>
<!--/row-->
</div>
<!--/.sidebar-offcanvas-->
</div>
</div>
<?php include 'blocks/footerInc.php'
This would be a very very simple page for what you want to archive.
<?php
//connection with database here.
if(isset($_POST['users']) && $_POST['users'] == 'approved'){
$sql = "your query";
$result = mysqli_query($mysql, $sql);
while($row = result->fetch_assoc()){
$users[] = $row;
}
}elseif(isset($_POST['users']) && $_POST['users'] == 'unapproved'){
$sql = "your query";
$result = mysqli_query($mysql, $sql);
while($row = result->fetch_assoc()){
$users[] = $row;
}
}elseif(isset($_POST['users']) && $_POST['users'] == 'other'){
$sql = "your query";
$result = mysqli_query($mysql, $sql);
while($row = result->fetch_assoc()){
$users[] = $row;
}
}
?>
<div>
<form action="" method="POST">
Approved<input type="radio" name="users" value="approved">
Unapproved<input type="radio" name="users" value="unapproved">
Other<input type="radio" name="users" value="other">
<input type="submit" value="Submit">
</form>
</div>
<div class="results">
<?php foreach ($users as $key => $value) {
?>
<div class="user">
<div><?php echo $value['firstName']; ?></div>
<div><?php echo $value['lastName']; ?></div>
</div>
<?php
} ?>
</div>

update form with 2 parts

hello everyone I am just starting PHP this year and I try to make form that is content 2 part first part main data second part it content table that I can add new row to enter data and this row content multi-select input and I try many times to write PHP code that I can update this form but I failed every time I try
<div class="modal-body">
<div class="form-group">
<label class="control-label col-sm-2" for="shop_name">اسم المحل:
<a style="color: red">*</a>
</label>
<div class="col-sm-3">
<input type="text" class="form-control" id="shop_name" value="<?php echo $strshop; ?>" name="shop_name" placeholder="اسم المحل" data-index="8">
</div>
<label class="control-label col-sm-2" for="cus_name">اسم العميل:
</label>
<div class="col-sm-3">
<input type="text" class="form-control" id="cus_name" name="cus_name" value="<?php echo $strcus; ?>" placeholder="اسمع العميل" data-index="9">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="cus_address">العنوان:<a style="color: red">*</a></label>
<div class="col-sm-3">
<input type="text" class="form-control" id="cus_address" name="cus_address" value="<?php echo $straddres; ?>" placeholder="عنوان" data-index="10">
</div>
<label class="control-label col-sm-2" for="tel"> التليفون:</label>
<div class="col-sm-3">
<input type="text" class="form-control" id="tel" name="tel" value="<?php echo $strtel; ?>" placeholder="تليفون" data-index="11">
</div>
</div>
</div>
<div class="modal-footer">
<h2>مياه</h2>
<div class="row clearfix">
<div class="col-md-12 column">
<?php
if (!empty($strid)) {
$q2 = "SELECT * FROM product_table WHERE form_id = $strid;";
$result = mysqli_query($con, $q2);
$count = mysqli_num_rows($result);
?>
<table class="table table-bordered table-hover" id="data_table">
<thead>
<tr>
<th class="text-center">
المنتج
</th>
<th class="text-center">
SKus
</th>
<th class="text-center">
الكمية
</th>
<th class="text-center">
ثلاجات
</th>
<th class="text-center">
مواد دعائية
</th>
<th class="text-center">
كمية الدعايه
</th>
<th>
action
</th>
</tr>
</thead>
<tbody>
<?php
if ($count > 0) {
while ($wrow = mysqli_fetch_array($result)) {
?>
<tr id='row'>
<td>
<input hidden name="wid" value="<?php echo $wrow['id'] ?>">
<select class="form-control" id="product_name" name="product_name[]" data-index="12">
<option selected disabled hidden>اختار المنتج .....</option>
<?php
$select_water = $con->query("select * from water");
if ($select_water->num_rows > 0) {
// output data of each row
while ($w = $select_water->fetch_assoc()) {
?>
<option <?php if ($wrow['product_name'] == $w['water_name']) echo "selected";?> ><?php echo $w['water_name']?></option>
<?php
}
} else {
echo "0 results";
}
?>
</select>
</td>
<td>
<select class="form-control" id="sk" name="sk[]"
data-index="6">
<option selected disabled hidden>اختار Skus</option>
<?php
$select_area = $con->query("select * from watersk");
if ($select_area->num_rows > 0) {
// output data of each row
while ($row2 = $select_area->fetch_assoc()) {
?>
<option <?php if ($wrow['sk'] == $row2['sk_name']) echo "selected"; ?> ><?php echo $row2 ['sk_name'] ?></option>
<?php
}
} else {
echo "0 results";
}
?>
</select>
</td>
<td>
<input type="number" id="qty" name="qty[]" value="<?php echo $wrow['qty']; ?>" placeholder='الكميه' class="form-control" data-index="16"/>
</td>
<td>
<input type="number" id="friz" name="friz[]" value="<?php echo $wrow['frizer']; ?>" placeholder='ثلاجه' class="form-control" data-index="17"/>
</td>
<td>
<?php
// var_dump($row['id']);
$water_id = $wrow['id'];
$test_array=array();
$select_water_market = $con->query("SELECT * FROM product_market WHERE water_id = $water_id;");
while ($row3 = $select_water_market->fetch_assoc()) {
$test_array[]= $row3['watermarket_media'];
}
// var_dump($test_array);
?>
<select multiple class="form-control" id="market_medi" name="market_media[0][]" data-index="6">
<?php
$select_media = $con->query("select * from market_media");
if ($select_media->num_rows > 0) {
// output data of each row
while ($row = $select_media->fetch_assoc()) {
?>
<?php if(in_array($row['media_name'],$test_array)){?>
<option selected>
<?php echo $row ['media_name'] ?>
</option>
<?php
}
else
{?>
<option>
<?php echo $row ['media_name'] ?>
</option>
<?php }
}
}else {
echo "0 results";
}
?>
</select>
</td>
<td>
<input style="float: right" type="number" id="market" name="market[]" placeholder="مواد دعائيه" class="form-control" value="<?php echo $wrow['mark_qty']; ?>" data-index="18"/>
</td>
<td>
<a class="btn btn-warning btn-sm" href='save/deleterow.php?id=".$delete['id']." data-toggle="modal" style="float: left;"><span class="glyphicon glyphicon-pencil"></span></a>
<a class="btn btn-danger btn-sm" href='save/deleterow.php?id=<?php echo $wrow['id'];?>&stid=<?php echo $strid;?>' data-toggle="modal" style="float: left;"><span class="glyphicon glyphicon-remove"></span></a>
</td>
</tr>
<?php
}
}
}
?>
</tbody>
</table>
<a class="btn btn-success btn-sm" href="" data-toggle="modal" onclick="addVariablesRow();" style="float: left;"><span class="glyphicon glyphicon-plus"></span></a>
</div>
<script>
function deleterow2(o) {
//no clue what to put here?
var p = o.parentNode.parentNode;
p.parentNode.removeChild(p);
}
var i = 1;
function addVariablesRow() {
var $t = $("#data_table");
var $row = $t.find("tbody tr").first();
var $r = $row.clone();
$r.attr('id', 'rrow' + i);
var $newRow = $r.find('input').val('').end().append("<td><a class='btn btn-danger btn-sm delete' onclick='deleterow2(this);' style='float: left;'><span class='glyphicon glyphicon-trash'></span></a></td>");
$newRow.appendTo($t).show();
$("#data_table tr:last td:first select").focus();
$('#market_medi').each(function () {
$(this).attr('name', 'market_media[' + i + '][]');
});
i++;
}
</script>
</div>
</div>

get value of checkbox submit to a variable

I'm trying to work out how to get the value of a checkbox submit it to a variable which is an id from a sql db.
Below is my current code:
-- Index.php
<?php
$sql = "SELECT * FROM `file`";
if (!$result = $db->query($sql)){
die('There was an error running the query [' . $db->error . ']');
}
?>
<form method="post">
<button class="btn btn-success">New</button>
<button type="submit" class="btn btn-warning">Edit</button>
<button class="btn btn-danger">Delete</button>
<table class="table table-condensed">
<thead>
<th>#</th>
<th>Name</th>
<th>Category</th>
<th>Date</th>
</thead>
<tbody>
<?php while($row = $result->fetch_assoc()){ ?>
<td><input type="checkbox" name="id_grab" value="<?php echo $row['file_id']; ?>"></td>
<td><?php echo $row['file_name']; ?></td>
<td><?php echo $row['file_category']; ?></td>
<td><?php echo date('d-m-y', strtotime($row['file_date'])); ?></td>
</tbody>
<?php } ?>
</table>
</form>
-- file_edit.php
<?php include('../db_connect.php') ;
$id=isset($_POST['id_grab']);
$sql = "SELECT * FROM `file` WHERE file_id = $id";
if (!$result = $db->query($sql)){
die('There was an error running the query [' . $db->error . ']');
}
$row = $result->fetch_assoc();
?>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">× </button>
<h4 class="modal-title" id="myModalLabel">Edit Invoice / Receipt</h4>
</div>
<div class="modal-body">
<form action="../includes/file_update.php" method="post" role="form" enctype="multipart/form-data">
<div class="form-group">
<label for="File_Name">Name</label>
<input type="text" name="file_name" class="form-control" id="file_name" value="<?php echo $row['file_name']; ?>">
</div>
<div class="form-group">
<lable for="File_Category">Category</label>
<input type="text" name="file_category" class="form-control" id="file_category" placeholder="Financial">
</div>
<div class="form-group">
<label for="file_tag">Tag</label>
<input type="text" name="file_tag" class="form-control" id="file_tag" placeholder="statement">
</div>
<div class="form-group">
<label for="file_description">Description</label>
<input type="text" name="file_description" class="form-control" id="file_description">
</div>
<div class="form-group">
<label for="file_date">Date</label>
<input type="date" name="file_date" class="form-control" id="file_date">
</div>
<div class="form-group">
<label for="file_location">File</label>
<input type="file" class="form-control" name="file_location" value="file">
<p class="help-block">Select appropriate file for upload.</p>
</div>
<button type="button" class="btn btn-info" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-success">Upload</button>
</form>
</div>
I can't work it out, spent hours looking online... My concern is at it's using Bootstraps Modal I wasn't sure if it would be able to grat the POST data... As if I enter the ID manually it works...
Any assistance would be greatly appreciated.
change this
$id=isset($_POST['id_grab']);
to
$id=isset($_POST['id_grab'])?$_POST['id_grab']:'';
//if id_grab dont have a value then $id value will be ''
isset() Returns TRUE if var exists and has value other than NULL, FALSE otherwise.

Categories