bootstrap table and form not visible in php - php

I am trying to get some data from a database and show them in a bootstrap table in php. but the php file only shows navigation bar. it does not show the table or the form. I have checked the connection which is fine. even if connection was wrong it should at least show the table headers and form labels. which it does not.
<?php
include 'adminlogincheck.php';
include 'dbcarsconfig.php';
include 'adminheader.php';
?>
<div class="container-fluid">
<div class="row justify-content-center">
<div class="col-md-8">
<!-- session response-->
<?php if(isset($_SESSION['response'])){ ?>
<div class="alert alert-<?= $_SESSION['res_type']; ?> alert-dismissible">
<button type="button" class="close" data-dismiss="alert">×</button>
<?= $_SESSION['response']; ?>
</div>
<?php } unset($_SESSION['response']);?>
<?php
$query="SELECT * FROM cars";
$stmt=$conn->prepare($query);
$stmt->execute();
$result=$stmt->get_result();
?>
<table class="table table-dark table-striped table-hover">
<thead>
<tr>
<th>Thumbnail</th>
<th>ID</th>
<th>Reg no</th>
<th>Make</th>
<th>Model</th>
<th>Price</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php while($row=$result->fetch_Assoc()){?>
<tr>
<td><img src="<?= $row['image1']?>" width="100" height="50"></td>
<td><?= $row['id']?></td>
<td><?= $row['carreg']?></td>
<td><?= $row['make']?></td>
<td><?= $row['model']?></td>
<td><?= $row['price']?></td>
<td> Edit/View</td>
<td> Delete</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<div class="col-md-4">
<form action="actioncars.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="id" value="<?= $id; ?>">
<div class="form-group">
<input type="text" name="carreg" class="form-control" placeholder="Enter car reg no" value="<?= $carreg; ?>" required>
</div>
<div class="form-group">
<input type="text" name="make" class="form-control" placeholder="Make of car" value="<?= $make; ?>" required>
</div>
<div class="form-group">
<input type="text" name="model" class="form-control" placeholder="Model" value="<?= $model; ?>" required>
</div>
<div class="form-group">
<input type="text" name="price" class="form-control" placeholder="Price" value="<?= $price; ?>" required>
</div>
<div class="form-group">
<input type="hidden" name="oldimage" value="<?= $image1; ?>">
<input type="file" name="image1" class="custom-file">
<img src="<?= $image1; ?>" width="120" class="img-thumbnail">
</div>
<div class="form-group">
<?php if ($update==true){ ?>
<input type="submit" name="update" class="btn btn-success btn-block" value="Update record">
<?php } else { ?>
<input type="submit" name="add" class="btn btn-primary btn-block" value="Add record">
<?php } ?>
</div>
</form>
</div>
</div>
</div>
<?php include 'footer.php'; ?>

Related

How to pass form values to bootstrap model form hidden fields

i need to pass form values to bootstrap model form hidden fields on form button click.
basically the button is form button that holds the value of pos_id from database and a hidden text field that holds pro_id from database and when use click "Apply" button a registration form in model is opened where i need to take input from user and also want to store hidden fields value to database along with user inputs
here is my code of form that i am submitting.
<?php
echo "<div class='mt-3'>
<table class='table table-striped'>
<thead>
<tr>
<th>Apply For</th>
<th>Description</th>
<th>Project Name</th>
<th>Type</th>
<th>Last Date</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>".$row['post_name'],"</td>
<td>".$row['post_desc'],"</td>
<td>".$row['proj_name'],"</td>
<td>".$row['proj_type'],"</td>
<td>".$row['last_date'],"</td>
<td>
<form id='post_apply' method='post' action=''>
<input type='hidden' value='".$row['proj_id'],"'","></input>
<button data-toggle='modal' data-target='#applymodal' type='button' name='apply_btn' value='".$row['post_id'],"'"," class='btn btn-success border float-right '>Apply</button>
</form>
</td>
</tr>
</tbody>
</table>
</div>";
}
}
else {
echo "<p class='alert alert-danger text-center'>No Posts Found</p>";
exit;
}
mysqli_close($conn);
and model code is as:
<!-- The Modal -->
<div class="modal fade" id="applymodal" role="dialog">
<div class="modal-dialog " style="max-width:600px;">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header bg-danger ">
<h1 class="modal-title text-center" color="white">New Registration</h1>
<button type="button" class="btn btn-danger" data-dismiss="modal">×</button>
</div>
<!-- Modal body -->
<div id="modalmain" class="modal-body">
<form class="form" action="signup.php" method="post" enctype="multipart/form-data">
<fieldset>
<!-- display form error messages -->
<?php include(INCLUDE_PATH . "/layouts/messages.php") ?>
<div class="form-group <?php echo isset($errors['firstname']) ? 'has-error' : '' ?>">
<label class="control-label">Firs Name</label>
<input type="text" name="first_name" id="first_name" class="form-control form-control-sm">
<?php if (isset($errors['firstname'])): ?>
<span class="help-block"><?php echo $errors['firstname'] ?></span>
<?php endif; ?>
<?php echo $row['post_id'];?>
</div>
<div class="form-group <?php echo isset($errors['last_name']) ? 'has-error' : '' ?>">
<label class="control-label">Last Name</label>
<input type="text" name="last_name" id="last_name" class="form-control form-control-sm">
<?php if (isset($errors['last_name'])): ?>
<span class="help-block"><?php echo $errors['last_name'] ?></span>
<?php endif; ?>
</div>
<div class="form-group <?php echo isset($errors['mobile']) ? 'has-error' : '' ?>">
<label class="control-label">Mobile</label>
<input type="text" name="mobile" id="mobile" class="form-control form-control-sm" data-inputmask=" 'mask' : '0399-9999999'" placeholder="Mobile">
<?php if (isset($errors['mobile'])): ?>
<span class="help-block"><?php echo $errors['mobile'] ?></span>
<?php endif; ?>
</div>
<div class="form-group <?php echo isset($errors['username']) ? 'has-error' : '' ?>">
<label class="control-label">CNIC Number</label>
<input type="text" name="username" id="username" class="form-control form-control-sm" data-inputmask="'mask': '99999-9999999-9'" placeholder="14 Digits CNIC Number" required="yes">
<?php if (isset($errors['username'])): ?>
<span class="help-block"><?php echo $errors['username'] ?></span>
<?php endif; ?>
</div>
<div class="form-group <?php echo isset($errors['email']) ? 'has-error' : '' ?>">
<label class="control-label">Email</label>
<input type="text" name="email" id="email" class="form-control form-control-sm" placeholder="Email Address">
<?php if (isset($errors['email'])): ?>
<span class="help-block"><?php echo $errors['email'] ?></span>
<?php endif; ?>
</div>
<div class="form-group <?php echo isset($errors['password']) ? 'has-error' : '' ?>">
<label class="control-label">Password</label>
<input type="password" name="password" id="password" class="form-control form-control-sm">
<?php if (isset($errors['password'])): ?>
<span class="help-block"><?php echo $errors['password'] ?></span>
<?php endif; ?>
</div>
<div class="form-group <?php echo isset($errors['passwordConf']) ? 'has-error' : '' ?>">
<label class="control-label">Password confirmation</label>
<input type="password" name="passwordConf" class="form-control form-control-sm">
<?php if (isset($errors['passwordConf'])): ?>
<span class="help-block"><?php echo $errors['passwordConf'] ?></span>
<?php endif; ?>
</div>
<input type="hidden" value="$_POST['proj_id'];"></input>
<input type="hidden" value="$_POST['post_id'];"></input>
<div class="form-group">
<button type="submit" name="signup_btn" class="btn btn-block btn-success ">Create Account</button>
</div>
</fieldset>
</form>
</div>
<!-- Modal footer -->
<div class="modal-footer">
<p class="text-start">Aready have an account? Sign in</p>
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
#salar zaidi: Thank you soo much for help.
This solution worked for me:
$("#post_apply").click(function() {
var proj = $(this).find("#proj_id").val();
var post = $(this).find("#apply_btn").val();
var postn = $(this).find("#post_name").val();
$("#field_proj_id").val(proj)
$("#field_post_id").val(post)
$("#field_post_n").val(postn)
});

How can I update user's data by clicking on the edit button?

Using php, I want to make the Edit button in register.php to display the form which shows fields that have the already existing user's data and then admin can update the data. I'm about to go crazy because of this thing it's been the third day in row not moving to the second step! I've watched many YT tutorials and explored many solutions here and in google as well, but couldn't actually figure out how to fix mine! Please if you know where my mistake is and what should I edit, do tell me and I will be more than happy to fix it.
These are my files:
register.php
<?php
session_start();
include('includes/header.php');
include('includes/navbar.php');
?>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#addadminprofile">
Add Admin Profile
</button>
<!-- Modal -->
<div class="modal fade" id="addadminprofile" 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">Add Admin Data</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<form action="code.php" method="POST">
<div class="modal-body">
<div class="form-group">
<label>Username </label>
<input type="text" name="username" class="form-control" required>
</div>
<div class="form-group">
<label>Full name </label>
<input type="text" name="full_name" class="form-control" required>
</div>
<div class="form-group">
<label>Email </label>
<input type="email" name="email" class="form-control" required>
</div>
<div class="form-group">
<label>Password </label>
<input type="password" name="password" class="form-control" required>
</div>
<div class="form-group">
<label>Confirm password </label>
<input type="password" name="cpassword" class="form-control" required>
</div>
<div class="form-group">
<label>Gender </label>
<input type="radio" name="gender" tabindex="1" value="Male">
<span> Male</span>
<input type="radio" name="gender" tabindex="2" value="Female">
<span> Female</span>
</div>
<div class="form-group">
<label>Age </label>
<input type="text" name="age" class="form-control" required>
</div>
<div class="form-group">
<label>Phone number </label>
<input type="text" name="phone_number" class="form-control" required>
</div>
<div class="form-group">
<label>Work durationr </label>
<input type="text" name="work_duration" class="form-control" required>
</div>
<div class="form-group">
<label >Food Category:</label>
<select name="food_category" class="form-control" required>
<option value="hot_cold_dishes">Hot/Cold Dishes</option>
<option value="desserts">Desserts</option>
<option value="drinks">Drinks</option>
</select>
</div>
<div class="form-group">
<label>IG Account </label>
<input type="text" name="ig_account" class="form-control" required>
</div>
<div class="form-group">
<label >State:</label>
<select name="state" class="form-control" required>
<option value="1">First</option>
<option value="2">Second</option>
<option value="3n">Third</option>
</select>
</div>
<div class="form-group">
<label>Postcode </label>
<input type="text" name="postcode" class="form-control" required>
</div>
<div class="form-group">
<label>City </label>
<input type="text" name="city" class="form-control" required>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button type="Submit" name="submit" class="btn btn-primary">Register</button>
</div>
</form>
</div>
</div>
</div>
<?php
/*
if(isset($_SESSION['success']) && $_SESSION['success'] != ''){
echo '<h2>'.$_SESSION['success'].'</h2>';
unset ($_SESSION['success']);
}
if(isset($_SESSION['status']) && $_SESSION['status'] != ''){
echo '<script>alert('.$_SESSION['status'].')</script>';
unset ($_SESSION['status']);
}
*/
?>
<div class="card shadow">
<div class="card-body">
<div class="table-responsive">
<?php
$connection = mysqli_connect("localhost", "root", "", "finalproject") or die ("<script>alert('Connection Failed.')</script>");
$sql = "SELECT * FROM users";
$result = mysqli_query($connection, $sql);
?>
<table class="table table-borderd" id="dataTable" width="30%" cellspecing="0">
<thead>
<tr>
<th>Username</th>
<th>Full Name</th>
<th>Email</th>
<th>Password</th>
<th>Age</th>
<th>Gender</th>
<th>Phone Number</th>
<th>Work Duration</th>
<th>Food Category</th>
<th>IG Account</th>
<th>State</th>
<th>Postcode</th>
<th>City</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<?php
if(mysqli_num_rows($result)>0){
while($row = mysqli_fetch_assoc($result)){
?>
<tr>
<td><?php echo $row['username']?></td>
<td><?php echo $row['full_name']?></td>
<td><?php echo $row['email']?></td>
<td><?php echo $row['password']?></td>
<td><?php echo $row['phone_number']?></td>
<td><?php echo $row['work_duration']?></td>
<td><?php echo $row['food_category']?></td>
<td><?php echo $row['ig_account']?></td>
<td><?php echo $row['state']?></td>
<td><?php echo $row['postcode']?></td>
<td><?php echo $row['city']?></td>
<td><?php echo $row['gender']?></td>
<td><?php echo $row['age']?></td>
<td>
<form action="first_register.php" method="POST">
<input type="hidden" name="edit_username" value="<?php echo $row['username'];?>">
<button type="submit" name="edit_button" class="btn btn-success">Edit</button>
</form>
</td>
<td>
<button type="submit" class="btn btn-danger">Delete</button>
</td>
</tr>
<?php
}
}
else{
echo "No record found";
}
?>
</tbody>
</table>
</div>
</div>
<?php
include('includes/script.php');
include('includes/footer.php');
?>
first_register.php
<?php
$connection = mysqli_connect("localhost", "root", "", "finalproject")or die ("<script>alert('Connection Failed.')</script>");
session_start();
include('includes/header.php');
include('includes/navbar.php');
?>
<div class="container-fluid">
<!-- DataTales Example -->
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary"> EDIT Admin Profile </h6>
</div>
<div class="card-body">
<?php
if(isset($_POST['edit_button']))
{
$username = $_POST['username'];
$query = "SELECT * FROM register WHERE username='$username' ";
$query_run = mysqli_query($connection, $query);
foreach($query_run as $row)
{
?>
<form action="code.php" method="POST">
<input type="hidden" name="edit_username" value="<?php echo $row['username'] ?>">
<div class="form-group">
<label> Full name </label>
<input type="text" name="edit_full_name" value="<?php echo $row['full_name'] ?>" class="form-control">
</div>
<div class="form-group">
<label>Email</label>
<input type="email" name="edit_email" value="<?php echo $row['email'] ?>" class="form-control"
placeholder="Enter Email">
</div>
<div class="form-group">
<label>Password</label>
<input type="password" name="edit_password" value="<?php echo $row['password'] ?>"
class="form-control" placeholder="Enter Password">
</div>
<div class="form-group">
<label>Gender</label>
<input type="radio" name="edit_gender" value="Male" class="form-control">
<span> Male</span>
<input type="radio" name="edit_gender" value="Female" class="form-control">
<span> Female</span>
</div>
<div class="form-group">
<label>Age</label>
<input type="text" name="edit_age" value="<?php echo $row['age'] ?>"
class="form-control">
</div>
<div class="form-group">
<label>Phone Number</label>
<input type="text" name="edit_phone_number" value="<?php echo $row['phone_number'] ?>"
class="form-control">
</div>
<div class="form-group">
<label>Work Duration</label>
<input type="text" name="edit_work_duration" value="<?php echo $row['work_duration'] ?>"
class="form-control">
</div>
<div class="form-group">
<label>Food Category</label>
<select name="food_category" class="form-control" required>
<option value="hot_cold_dishes">Hot/Cold Dishes</option>
<option value="desserts">Desserts</option>
<option value="drinks">Drinks</option>
</select>
</div>
</div>
<div class="form-group">
<label>IG Account</label>
<input type="text" name="edit_ig_account" value="<?php echo $row['ig_account'] ?>"
class="form-control">
</div>
<div class="form-group">
<label>State</label>
<select name="state" class="form-control" required>
<option value="1">First</option>
<option value="2">Second</option>
<option value="3n">Third</option>
</select>
</div>
<div class="form-group">
<label>Postcode</label>
<input type="text" name="edit_postcode" value="<?php echo $row['postcode'] ?>"
class="form-control">
</div>
<div class="form-group">
<label>City</label>
<input type="text" name="edit_city" value="<?php echo $row['city'] ?>"
class="form-control">
</div>
<form action="edit_register.php" method="POST">
<input type="hidden" name="edit_username" value="<?php echo $row['username'];?>">
<button type="submit" name="edit_button" class="btn btn-success">Edit</button>
</form>
</form>
<?php
}
}
?>
<?php
include('includes/script.php');
include('includes/footer.php');
?>
edit_register.php
<?php
$connection = mysqli_connect("localhost", "root", "", "finalproject")or die ("<script>alert('Connection Failed.')</script>");
session_start();
include('includes/header.php');
include('includes/navbar.php');
?>
<div class="card shadow">
<div class="card-header">
<h6 class="font-weight-bold text-primary">EDIT Profile </h6>
</div>
<div class="card_body">
<?php
if(isset($_POST['updatebtn']))
{
$username2 = $_POST['edit_username'];
$full_name2 = $_POST['edit_full_name'];
$email2 = $_POST['edit_email'];
$password2 = $_POST['edit_password'];
$cpassword2 = $_POST['cpassword'];
$phone_number2 = $_POST['edit_phone_number'];
$work_duration2 = $_POST['edit_work_duration'];
$food_category2 = $_POST['edit_food_category'];
$ig_account2 = $_POST['edit_ig_account'];
$state2 = $_POST["edit_state"];
$postcode2 = $_POST['edit_postcode'];
$city2 = $_POST['edit_city'];
$gender2 = $_POST['edit_gender'];
$age2 = $_POST['edit_age'];
$query = "UPDATE users SET username='$username2', full_name='$full_name2', email='$email2', password='$password2', phone_number='$phone_number2', word_duration='$work_duration2', food_category='$food_category2',
ig_account='$ig_account2', state='$state2', postcode='$postcode2', city='$city2', gender='$gender2', age='$age2' WHERE username='$username2'";
$query_run = mysqli_query($connection, $query);
if($query_run)
{
$_SESSION['status'] = "Your Data is Updated";
$_SESSION['status_code'] = "success";
header('Location: register.php');
}
else
{
$_SESSION['status'] = "Your Data is NOT Updated";
$_SESSION['status_code'] = "error";
header('Location: register.php');
}
?>
<?php
}
?>
</div>
<?php
include('includes/script.php');
include('includes/footer.php');
?>
At register.php, you have this line this -
<input type="hidden" name="edit_username" value="<?php echo $row['username'];?>">
So at first_register.php, you should have this line like this instead -
$username = $_POST['username']; to $username = $_POST['edit_username'];
and this line like this instead -
<form action="code.php" method="POST"> to <form action="edit_register.php" method="POST">
i could see you have a form inside a another form like this
<form action="edit_register.php" method="POST">
<input type="hidden" name="edit_username" value="<?php echo $row['username'];?>">
<button type="submit" name="edit_button" class="btn btn-success">Edit</button>
</form>
//remove the form tag to this only since you have input for edit_username aready at the top of your form
<button type="submit" name="edit_button" class="btn btn-success">Edit</button>
//and finally at edit_register.php change
if(isset($_POST['updatebtn']))
to if(isset($_POST['edit_button']))
I guess this should help achieve the goal. good luck

Laravel: Undefined variable in #foreach

I want to display order_details table on web, but #foreach loop says Undefined variable $order_details
Here is my #foreach loop
#foreach($order_details as $order_detail)
<tr>
<td>{{$order_detail->product_id}}</td>
<td>{{$order_detail->name}}</td>
<td>{{$order_detail->phone}}</td>
</tr>
#endforeach
My order controller contains this:
public function index()
{
$order_details=Order_Detail::all();
return view('orders.index',['order_details' => $order_details]);
}
index.blade.php contains only css and javascript code.
my index.blade.php is further connected to livewire(order.blade.php) like this
#livewire('order')
my livewire(order.blade.php) contains this code
<div class="col-lg-12">
<div class="row">
<div class="col-md-8">
<div class="card">
<div class="card-header"><h4 style="float:left">Order Products</h4>
<a href="#" style="float:right" class="btn btn-dark"
data-toggle="modal" data-target="#addproduct">
<i class="fa fa-plus"></i>Add new Product </a></div>
<div class="card-body">
<div class="my-2">
<form wire:submit.prevent="InsertoCart">
<input type="text" name="" wire:model="product_code"
id="" class="form-control" placeholder="Enter Product code">
</form>
</div>
#if(session()->has('success'))
<div class="alert alert-success">
{{session('success')}}
</div>
#elseif(session()->has('info'))
<div class="alert alert-info">
{{session('info')}}
</div>
#elseif(session()->has('error'))
<div class="alert alert-danger">
{{session('error')}}
</div>
#endif
<Table class="table table-bordered table-left">
<thead>
<tr>
<th></th>
<th>Product Name</th>
<th>Qty</th>
<th>Price</th>
<th>Discount (%)</th>
<th colspan="6">Total</th>
</tr>
</thead>
<tbody class="addMoreProduct">
#foreach($productIncart as $key=> $cart)
<tr>
<td class="no">{{$key + 1}}</td>
<td>
<input type="text" class="form-control" value="{{$cart->product->product_name}}">
</td>
<td width="15%">
<div class="row">
<div class="col-md-2">
<button wire:click.prevent="IncrementQty({{$cart->id}})"
class="btn btn-sm btn-success"> + </button>
</div>
<div class="col-md-1">
<label for="">{{$cart->product_qty}}</label>
</div>
<div class="col-md-2">
<button wire:click.prevent="DecrementQty({{$cart->id}})"
class="btn btn-sm btn-danger"> - </button>
</div>
</div>
</td>
<td>
<input type="number"
value="{{$cart->product->price}}" class="form-control">
</td>
<td>
<input type="number"
class="form-control">
</td>
<td>
<input type="number"
value="{{$cart->product_qty * $cart->product->price}}"
class="form-control total_amount">
</td>
<td><a href="#" class="btn btn-sm btn-danger rounded-circle">
<i class="fa fa-times" wire:click="removeProduct({{$cart->id}})"></i>
</a></td>
</tr>
#endforeach
</tbody>
</table>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card">
<div class="card-header">
<h4>Total <b class="total1">{{$productIncart->sum('product_price')}}</b></h4>
</div>
<form action="{{route('orders.store')}}" method="POST">
#csrf
#foreach($productIncart as $key=> $cart)
<input type="hidden" class="form-control" name="product_id[]" value="{{$cart->product->id}}">
<!-- <input type="hidden" name="product_name[]" value="{{$cart->product_name}}"> -->
<input type="hidden" name="quantity[]" value="{{$cart->product_qty}}">
<input type="hidden" name="price[]"
value="{{$cart->product->price}}" class="form-control price" >
<input type="hidden" name="discount[]"
class="form-control discount" >
<input type="hidden" name="total_amount[]"
value="{{$cart->product_qty * $cart->product->price}}"
class="form-control total_amount" >
#endforeach
<div class="card-body">
<div class="btn-group">
<button type="button"
onclick="PrintReceiptContent('print')"
class="btn btn-dark"> <i class="fa fa-print"></i>Print
</button>
<button type="button"
onclick="PrintReceiptContent('print')"
class="btn btn-primary"> <i class="fa fa-print"></i>History
</button>
<button type="button"
onclick="PrintReceiptContent('print')"
class="btn btn-danger"> <i class="fa fa-print"></i>Report
</button>
</div>
<div class="panel">
<div class="row">
<table class="table table-striped">
<tr>
<td>
<label for="">Customer Name</label>
<input type="text" name="customer_name" id="" class="form-control">
</td>
<td>
<label for="">Customer Phone</label>
<input type="number" name="customer_phone" id="" class="form-control">
</td>
</tr>
</table>
<td>Payment Method <br>
<div class="">
<span class="radio-item">
<input type="radio" name="payment_method" id="payment_method"
class="true" value="cash" checked="checked">
<label for="payment_method"><i class="fa fa-money-bill text-success"></i>Cash</label>
</span>
<span class="radio-item">
<input type="radio" name="payment_method" id="payment_method"
class="true" value="bank transfer">
<label for="payment_method"><i class="fa fa-university text-danger"></i>Bank Transfer</label>
</span>
<span class="radio-item">
<input type="radio" name="payment_method" id="payment_method"
class="true" value="credit Card">
<label for="payment_method"><i class="fa fa-credit-card text-info"></i>Credit Card</label>
</span>
</td><br>
<td> Payment
<input type="number" wire:model="pay_money" name="paid_amount"
id="paid_amount" class="form-control">
</td>
<td> Returning Change
<input type="number" wire:model="balance" name="balance"
id="balance" readonly class="form-control">
</td>
<td>
<button class="btn-primary btn-lg btn-block mt-3">Save</button>
</td>
<td>
<button class="btn-danger btn-lg btn-block mt-2">Calculator</button>
</td>
<div class="text-center">
<i class=" fa fa-sign-out-alt"></i>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
<!-- Order Details display -->
<div class="container-fluid">
<div class="col-lg-12">
<div class="row">
<div class="col-md-9">
<div class="card">
<div class="card-header"><h4 style="float:left">Recent Orders</h4>
</div>
<div class="card-body">
<Table class="table table-bordered table-left">
<thead>
<tr>
<th>id</th>
<th>Order Id</th>
<th>Product Name</th>
<th>Quantity</th>
<th>Price</th>
<th>Total Amount</th>
<th>Discount</th>
</tr>
</thead>
#foreach($order_details as $order_detail)
<tr>
<td>{{$order_detail->product_id}}</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td>{{$order_detail->unitprice}}</td>
<td>{{$order_detail->amount}}</td>
<td></td>
</tr>
#endforeach
<tbody>
</Table>
</div>
</div>
</div>
</div>
</div>
</div>
What I noticed in your code is that you might be expecting an answer in another place while your code is running somewhere else.
First of all, you are writing a show(Order $order) function that collects parameters, while you are outputting it in the index page, so where you are calling the show function will expect a parameter, while the index will not expect a parameter

How to pass the id of the record as GET variable for the modal in edit link buttons?

I need to select a record in the modal form. The HTML code is,
<table class="table justify-content-center" style="background-color:white">
<input type="hidden" name="id" value="<?php echo $id; ?>">
<thead style="background-color:green;color:white;font-weight:bold">
<tr>
<th>Employee Name</th>
<th>Employee ID</th>
<th>Designation</th>
<th>Phone</th>
<th>Actions</th>
</tr>
</thead>
<?php
while ($row = $result->fetch_assoc()): ?>
<tr>
<td><?php echo $row['employeename']; ?></td>
<td><?php echo $row['employeeno']; ?></td>
<td><?php echo $row['designation']; ?></td>
<td><?php echo $row['contactnumber']; ?></td>
<td>
<button name="edit" class="editbtn"> <a href="#editEmployeeModal" data-toggle="modal" data-dismiss="modal" style="color: brown" >Edit</a> </button>
<button name="delete" class="btn btn-info " >Delete </button>
</td>
</tr>
<?php endwhile; ?>
</table>
and the HTML for modal form is,
<!-- Edit Modal HTML -->
<div id="editEmployeeModal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<form action="employeeprocess.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="id" value="<?php echo $id; ?>">
<div class="modal-header">
<h4 class="modal-title">Edit Employee</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<div class="form-group">
<label>Employee Number</label>
<input type="text" class="form-control" value="<?php $employeenum ?>" name="employeenum" required>
</div>
<div class="form-group">
<label>Employee Name</label>
<input type="text" class="form-control" name="employeename" value="<?php $employeename ?>" required>
</div>
<div class="form-group">
<label>Job Location</label>
<input type="text" class="form-control" name="joblocation" value="<?php $joblocation ?>" required>
</div>
<div class="form-group">
<label>DateofJoin</label>
<input type="date" class="form-control" name="dateofjoin" value="<?php $dateofjoin ?>" required>
</div>
<div class="form-group">
<label>Contact Number</label>
<input type="text" class="form-control" name="contactnumber" value="<?php $contactnumber ?>" required>
</div>
<div class="form-group">
<label>Designation</label>
<input type="text" class="form-control" name="designation" value="<?php $designation ?>" required>
</div>
<div class="form-group">
<label>Status</label>
<input type="text" class="form-control" name="status" value="<?php $status ?>" required>
</div>
<div class="form-group">
<label>Photo</label>
<input type="file" class="form-control" name="myfile" required>
</div>
</div>
<div class="modal-footer">
<input type="button" class="btn btn-default" data-dismiss="modal" value="Cancel">
<input type="submit" class="btn btn-success" name="edit" value="Update">
</div>
</form>
</div>
</div>
</div>
employeeprocess.php
if (isset($_GET['delete'])){
$id = $_GET['delete'];
$mysqli->query("DELETE FROM employees WHERE id=$id") or die($mysqli->error());
$_SESSION['message'] = "Record has been deleted!";
$_SESSION['msg_type'] = "danger";
header("location: employeelist.php");
}
if (isset($_GET['edit'])){
$id = $_GET['edit'];
$update = true;
$result = $mysqli->query("SELECT * FROM employees WHERE id=$id") or die($mysqli->error());
if (count($result)==1){
$row = $result->fetch_array();
$employeenum = $row['employeenum'];
$employeename = $row['employeename'];
$joblocation = $row['joblocation'];
$dateofjoin = $row['dateofjoin'];
$contactnumber = $row['contactnumber'];
$designation = $row['designation'];
$status = $row['status'];
}
}
Javascript is
<script>
$(".editbtn").click(function () {
$('#edit').val($(this).data('id'));
});
</script>
I need to pass the selected record to the editEmployeeModal and set the variable edit for modal dialog to display the selected record. The modal is not working, if I put the statement href="#editEmployeeModal?edit= <?php echo $row['id']; ?>" So, Can you suggest me to this problem?
You can set a data attribute as id of your row in the for loop and bind an onClick event to a js function to update the form id field:
<button name="edit" class="btn btn-info"> <a href="#editEmployeeModal" data-toggle="modal" data-dismiss="modal" style="color: brown" data-rowid="<?=$row['id']; ?>" onClick="updateId()" >Edit</a> </button>
JavaScript
function updateId(){
let id = this.getAttribute('data-rowid');
document.getElementsByName("id")[0].value = id;
}
You could alternatively pass the id to the updateId function as a parameter instead of setting the data attribute.

how can i show only selected checkbox productcode and price in codeIgniter

My view is like i want to show the selected textbox price and code to the controller
how can i do this
<div>
<!--second line start-->
<?php
foreach ($enq_info as $ei) {
echo form_open_multipart("Quotation/prepareQuote2/$ei->eid");
if (!empty($quote_data)) {
?>
<input name="quote_check" value="1" type="text" class="form-control">
<?php
} else {
?>
<input name="quote_check" value="no" type="text" class="form-control">
<?php
}
?>
<div class="form-group">
<div class="col-sm-2">
<label for="firstname">Enquiry Id</label>
<input name="e_id" id="e_id" value="<?php echo $ei->eid;?>" type="text" class="form-control">
</div>
<div class="col-sm-3">
<label for="lastname">Company Name</label>
<input type="text" name="company_name" id="company_name" value="<?php echo $ei->company_name;?>" class="form-control" />
</div>
<div class="col-sm-3">
<label for="lastname">Contact Person</label>
<input type="text" name="c_person" id="c_person" value="<?php echo $ei->c_person;?>" class="form-control"/>
</div>
<div class="col-sm-4">
<label>Address</label>
<textarea class="form-control" id="address" name="address" value="<?php echo $ei->address;?>"><?php echo $ei->address;?></textarea>
</div>
</div>
<div class="form-group">
<div class="col-sm-3">
<label for="firstname">Attn Department</label>
<textarea class="form-control" id="dept" name="dept" value="">
<?php
echo $ei->c_person." Tel ";
if(empty($ei->p_contact))
echo $ei->c_contact;
else
echo $ei->p_contact;
?>
</textarea>
</div>
<div class="col-sm-3">
<label for="lastname">Quotation For</label>
<select id="quotation_type" name="quotation_type" class="form-control m-b">
<option value="Q_Manager">Q-Manager Quote</option>
<option value="Q_Master">Q-Master Quote</option>
<option value="Q_Manager_repair">Q-Manager Repair Quote</option>
</select>
</div>
<div class="col-sm-3">
<label for="lastname">Discount</label>
<textarea class="form-control" id="discount" name="discount"></textarea>
</div>
<div class="col-sm-3">
<label for="lastname"></label><br><br>
<input type="submit" class="btn btn-success" id="default_quote" value="Generate Default Quote" onClick="rerurn disable1();"/>
</div>
</div>
<div id="showquote">
<div class="row">
<div class="hpanel">
<div class="panel-body">
<div class="col-md-12">
<table class="table table-bordered table-striped">
<tr>
<td>Product Name</td>
<td>Product Code</td>
<td>Price</td>
<td>Action</td>
</tr>
<?php
// print_r($quote_data);
foreach ($product_data as $qd) {
?>
<tr>
<td><?php echo $qd->cp_name;?></td>
<td><?php echo $qd->cp_code;?></td>
<td>
<input type="text" name="product_price[]" value="<?php echo $qd->p_price;?>">
</td>
<td>
<input type="checkbox" name="product_name[]" value="<?php echo $qd->cp_name;?>" checked/>
</td>
</tr>
<?php
}
?>
</table>
</div>
</div>
</div>
</div>
</div>
<?php echo form_close(); ?>
<br><br>
<!--for new manual quote-->
<?php
}
?>
<!--third line start-->
how can i send the selected values price and also product code to the controller
just add the product code - product price with comma seperated in a hidden field like below
12-20000,13-30000,14-200 and so on
and once received in controller process it with explode or other way.
hopes you understood.

Categories