I have problem with displaying the table when I put 2 Sql queries inside 1 page. I don't have this problem when I only put 1 query.
I wanted to display the list of student from the student table and the the lecturer can add the student to be put under their care which will have the add function. I have done the coding but I encountered problem.
this is my code
<table id=" table" class="table table-bordered">
<thead>
<tr>
<th>Student ID</th>
<th>Name</th>
<th>Email</th>
<th>Contact Number</th>
<th>Programme Type</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$query = mysqli_query($conn, "SELECT * FROM `student`") or die(mysqli_error());
while($fetch = mysqli_fetch_array($query)){
?>
<tr class="del_student<?php echo $fetch['student_id']?>">
<td><?php echo $fetch['student_id']?></td>
<td><?php echo $fetch['student_name']?></td>
<td><?php echo $fetch['student_email']?></td>
<td><?php echo $fetch['contact_number']?></td>
<td><?php echo $fetch['programme_type']?></td>
<td><?php echo $fetch['status_type']?></td>
<td><center><button class="btn btn-warning" data-toggle="modal" data-target="#edit_modal<?php echo $fetch['student_id']?>"><span class="glyphicon glyphicon-edit"></span> Edit</button> </center>
</td>
</tr>
<div class="modal fade" id="edit_modal<?php echo $fetch['student_id']?>" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<form method="POST" action="update_student.php">
<div class="modal-header">
<h4 class="modal-title">Add Supervisee</h4>
</div>
<div class="modal-body">
<div class="col-md-3"></div>
<div class="col-md-6">
<div class="form-group">
<label>Student ID</label>
<input type="hidden" name="id" value="<?php echo $fetch['id']?>" class="form-control"/>
<input type="number" name="student_id" value="<?php echo $fetch['student_id']?>" class="form-control" required="required"/>
</div>
<div class="form-group">
<label>Student Name</label>
<input type="text" name="student_name" value="<?php echo $fetch['student_name']?>" class="form-control" required="required"/>
</div>
<div class="form-group">
<label>Student Email</label>
<input type="email" name="student_email" value="<?php echo $fetch['student_email']?>" class="form-control" required="required"/>
</div>
<div class="form-group">
<label>Contact Number </label>
<input type="text" name="contact_number" value="<?php echo $fetch['contact_number']?>" class="form-control" required="required"/>
</div>
<div class="form-group">
<label>Programme Type</label>
<input type="text" name="programme_type" value="<?php echo $fetch['programme_type']?>" class="form-control" required="required"/>
</div>
<div class="form-group">
<label>Status</label>
<input type="text" name="status_type" value="<?php echo $fetch['status_type']?>" class="form-control" required="required"/>
</div>
<label>Supervisor Information</label>
<div class="form-group">
<?php
$query = mysqli_query($conn, "SELECT * FROM `supervisor` WHERE `user_id` = '$_SESSION[user]'") or die(mysqli_error());
$fetch = mysqli_fetch_array($query);
$user_id = $fetch['work_id'];
?>
<label>Supervisor ID</label>
<input type="text" name="supervisor_id" value="<?php echo $fetch['work_id']?>" class="form-control" required="required"/>
</div>
<div class="form-group">
<label>Supervisor Name</label>
<input type="text" name="supervisor_name" value="<?php echo $fetch['name']?>" class="form-control" required="required"/>
</div>
<div class="form-group">
<label>Supervisor Role </label>
<select name="supervisor_role" class="form-control" required="required">
<option value="Chose supervisor role"></option>
<option value="Supervisor">Supervisor</option>
<option value="Co - Supervisor">Co-Supervisor</option>
</select>
</div>
</div>
</div>
<div style="clear:both;"></div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal"><span class="glyphicon glyphicon-remove"></span> Close</button>
<button name="update" class="btn btn-warning" ><span class="glyphicon glyphicon-save"></span> Update</button>
</div>
</form>
</div>
</div>
<?php
}
?>
</tbody>
</table>
</div>
</div>
I noticed that the table did not display the full list of student when I put this query
<?php
$query = mysqli_query($conn, "SELECT * FROM `supervisor` WHERE `user_id` = '$_SESSION[user]'") or die(mysqli_error());
$fetch = mysqli_fetch_array($query);
$user_id = $fetch['work_id'];
?>
What I want to achieve is I want to display all the student that have been registered inside the database, and the lecturer can add the student, student information alongside with the lecturer id and name will be saved into the database. How to fix this problem?
You are using $fetch to get results from both queries.
Here's what is happening in your code.
your $fetch gets results from students table.
displays the table content till it reaches the 2nd query.
when your 2nd query gets executed, $fetch values gets changed. Thus only 1 row is displayed for your student's table.
Change the $fetch in 2nd query to something else, like $fetch2
Related
Main Goal: I want to view the whole details of my specific row data in my table into a new form(input text) based on their ID.
Here is my code to fetch my data into table
<?php
include 'connection.php';
$query = "SELECT * FROM appointment WHERE request_status = 2 AND appoint_active = 1";
$run = mysqli_query($conn,$query);
?>
<div class="row">
<div class="col-md-12">
<div class="panel panel-success">
<div class="panel-heading">Listing All Services</div>
<div class="panel-body">
<table class="tables" id="manageMainteTable" style="width:100%;">
<tr>
<th style="text-align: center;">Service ID</th>
<th style="text-align: center; width:150px;">Order Date</th>
<th style="text-align: center;">Client Name</th>
<th style="text-align: center;">Contact</th>
<th style="text-align: center;">Client Product</th>
<th style="text-align: center;">No. of Items</th>
<th style="text-align: center; width:150px;">Due Date</th>
<th style="text-align: center;">Service Status</th>
<th style="text-align: center;">Action</th>
</tr>
<?php
if ($num = mysqli_num_rows($run)>0) {
while ($result = mysqli_fetch_assoc($run)) {
echo "
<tr>
<td>".$result['appoint_id']."</td>
<td>".$result['order_date']."</td>
<td>".$result['customer_name']."</td>
<td>".$result['customer_contact']."</td>
<td>".$result['item_type']."</td>
<td>".$result['quantity']."</td>
<td>".$result['due_date']."</td>";
if($result['appoint_status'] == 2 ){
echo"<td><label class='label label-success'>Finished</label></td>";
} else {
echo"<td><label class='label label-danger'>On Going</label</td>";
}
if($result['appoint_status'] == 2 ){
echo "<td>
<button class='btn btn-sm btn-info edit_cat' data-toggle='modal' data-target='#addProductModal'> VIEW </button>
<a href='php_action/finishAppointRemove.php?appoint_id=".$result['appoint_id']."' class='btn btn-sm btn-success edit_cat' id='dltbtn'>Remove</a></td>";
} else {
echo "<td>
<button class='btn btn-sm btn-info edit_cat' data-toggle='modal' data-target='#addProductModal'>VIEW</button>
<a href='php_action/finishAppoint.php?appoint_id=".$result['appoint_id']."' class='btn btn-sm btn-success edit_cat' id='fnhbtn'>Finished</a></td>";
}
}
}
?>
</tr>
</table>
</div>
</div>
</div>
</div>
So what i want is when i click this button **
<button class='btn btn-sm btn-info edit_cat' data-toggle='modal' data-target='#addProductModal'> VIEW </button>
** The corresponding row will fetch its data into input boxes.
<div class="modal" tabindex="-1" role="dialog" id="addProductModal">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Full Details</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<form class="form-horizontal" id="submitProductForm" action="php_action/updateMainte.php" method="POST">
<div class="modal-body">
<div id="add-product-messages"></div>
<div class="form-group">
<label class="control-label col-sm-3" for="appointID">Appoint ID:</label>
<div class="col-sm-9">
<input type="number" class="form-control" id="appointID" name="appoint" placeholder="Appoint ID" value="<?php echo $row['appoint_id'];?>" required>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="customerName">Customer Name:</label>
<div class="col-sm-9">
<input type="text" class="form-control" id="customerName" name="customerName" placeholder="Customer Name" required>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="contact">Contact Number:</label>
<div class="col-sm-9">
<input type="text" class="form-control" id="contact" name="contact" placeholder="Contact #" required>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="item_type">Item/s Type:</label>
<div class="col-sm-9">
<input type="text" class="form-control" id="item_type" name="item_type" placeholder="Items" required>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="quantity">Quantity:</label>
<div class="col-sm-9">
<input type="number" class="form-control" id="quantity" name="quantity" placeholder="Quantity" min="1" required>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="due">Due Date:</label>
<div class="col-sm-9">
<input type="text" class="form-control" id="due" name="due" placeholder=" Due Date" required>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="worker" required>Assinged Worker/s:</label>
<div class="col-sm-9">
<select class="form-control" id="worker" name="worker">
<option value="">---Select---</option>
<?php
$sql = "SELECT brand_id, brand_name FROM brands WHERE brand_status = 1 AND brand_active = 1";
$result = $connect->query($sql);
while ($row = $result->fetch_array()){
echo "<option value='".$row[0]."'>".$row[1]."</option>";
}
?>
</select>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary" id="createProductBtn" data-loading-text="Loading..">Update Information</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
}
}
</form>
</div>
</div>
</div>
This is the visual example of my table.
And when i click the view button
So what i want is to automatically fetch the correspoding row of the view button that i just clicked. Im kinda new to coding so im not really sure what i need to do that. Thanks and sorry for convenience.
Step 1: Add a appoint_id (i.e. unique id ) to view button using data attribute.
In Your Case data-appoint='".$result['appoint_id']."'
echo "<td>
<button class='btn btn-sm btn-info edit_cat' data-appoint='".$result['appoint_id']."' data-toggle='modal' data-target='#addProductModal'> VIEW </button>";
-Step 2: Add a onclick event listener to view button. In Your Case
$(".edit_cat").click(function(){
let service_id=$(this).data('appoint');
console.log(service_id);
});
so you can able to access service id in function so add ajax or fetch api to request the source and get data from it. And add Data to desired Input
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
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.
Line 3
edit_accounts.php
<?php $get_id = $_GET['id']; ?>
<?php// $get_id = isset($_POST['id']) ? $_POST['id'] : ''; ?>
<div class="container">
<div class="margin-top">
<div class="row">
<div class="span12">
<?php
$query=mysqli_query($dbcon,"select * from users_tbl where id ='$get_id'")or die(mysqli_error());
$row=mysqli_fetch_array($query);
$id=$row['id'];
?>
<div class="alert alert-info"><i class="icon-pencil"></i> Edit Member</div>
<p><a class="btn btn-info" href="users.php"><i class="icon-arrow-left icon-large"></i> Back</a></p>
<div class="addstudent">
<div class="details">Please Enter Details Below</div>
<form class="form-horizontal" method="POST" action="update_accounts.php" enctype="multipart/form-data">
<div class="control-group">
<label class="control-label" for="inputEmail">User_ID:</label>
<div class="controls">
<input type="text" id="inputEmail" value="<?php echo $row['code'];?>" name="code" >
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputEmail">Username:</label>
<div class="controls">
<input type="text" id="inputEmail" name="username" maxlength="30" value="<?php echo $row['username'];?>" >
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputPassword">Firstname:</label>
<div class="controls">
<input type="text" id="inputPassword" name="firstname" maxlength="30" value="<?php echo $row['firstname'];?>" >
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputPassword">Middlename:</label>
<div class="controls">
<input type="text" id="inputPassword" name="middlename" maxlength="30" value="<?php echo $row['middlename'];?>" >
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputEmail">Lastname:</label>
<div class="controls">
<input type="text" id="inputEmail" name="lastname" value="<?php echo $row['lastname'];?>" >
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputEmail">Email:</label>
<div class="controls">
<input type="email" id="inputEmail" name="email" value="<?php echo $row['email'];?>" >
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputEmail">Address:</label>
<div class="controls">
<input type="text" id="inputEmail" name="address" value="<?php echo $row['address'];?>" >
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputEmail">Contact No:</label>
<div class="controls">
<input type="text" id="inputEmail" name="contact_number" maxlength="11" value="<?php echo $row['contact_number'];?>">
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputEmail">Position:</label>
<div class="controls">
<input type="text" id="inputEmail" name="position" value="<?php echo $row['position'];?>" >
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputEmail">User Type:</label>
<div class="controls">
<input type="text" id="inputEmail" name="type_id" value="<?php echo $row['type_id'];?>" >
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputEmail">BirthDate:</label>
<div class="controls">
<input type="date" id="inputEmail" name="birthdate" value="<?php echo $row['birthdate'];?>">
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputEmail">Date Started:</label>
<div class="controls">
<input type="date" id="inputEmail" name="date_started" value="<?php echo $row['date_started'];?>">
</div>
</div>
<div class="control-group">
<div class="controls">
<button name="submit" type="submit" class="btn btn-success"><i class="icon-save icon-large"></i> Update</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<?php
if (isset($_POST['submit'])){
$usercode=$_POST['code'];
$username=$_POST['username'];
$firstname=$_POST['firstname'];
$middlename=$_POST['middlename'];
$lastname=$_POST['lastname'];
$type_id=$_POST['type_id'];
$birthdate=$_POST['birthdate'];
$address = $_POST['address'];
$email=$_POST['email'];
$password="qwerty";
$contact_number=$_POST['contact_number'];
$position=$_POST['position'];
$date_started=$_POST=['date_started'];
mysqli_query($dbcon,"UPDATE users_tbl set
code='$usercode',firstname='$firstname',lastname='$lastname',middlename = '$middlename',
lastname = '$lastname',type_id = '$type_id',birthdate = '$birthdate',address = '$address',email = '$email',password = '$password',
contact_number = '$contact_number',position = '$position',date_started = '$date_started' where id='$id'")or die(mysqli_error());
?>
<script>alert('Update Status Successful!');
window.location='accounts.php';</script>;
<?php
}
?>
accounts.php
<thead>
<tr>
<th>User ID:</th>
<th>Username</th>
<th>Firstname</th>
<th>Middlename</th>
<th>Lastname</th>
<th>Email</th>
<th>Address</th>
<th>Contact No.</th>
<th>Position</th>
<th>User Type:</th>
<th>Birthdate:</th>
<th>Date Started</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php $user_query=mysqli_query($dbcon,"select * from users_tbl")or die(mysqli_error());
while($row=mysqli_fetch_array($user_query)){
$id=$row['id']; ?>
<tr class="del<?php echo $id ?>">
<td><?php echo $row['code']; ?></td>
<td><?php echo $row['username']; ?></td>
<td><?php echo $row['firstname']; ?></td>
<td><?php echo $row['middlename']; ?></td>
<td><?php echo $row['lastname']; ?></td>
<td><?php echo $row['email']; ?></td>
<td><?php echo $row['address']; ?></td>
<td><?php echo $row['contact_number']; ?></td>
<td><?php echo $row['position']; ?></td>
<td><?php echo $row['type_id']; ?></td>
<td><?php echo $row['birthdate']; ?></td>
<td><?php echo $row['date_started']; ?></td>
<td class="action">
<a rel="tooltip" title="Delete" id="<?php echo $id; ?>" href="#delete_book<?php echo $id; ?>" data-toggle="modal" class="btn btn-danger"><i class="icon-trash icon-large"></i></a>
<?php include('delete_book_modal.php'); ?>
<a rel="tooltip" title="Edit" id="<?php echo $id; ?>" href="edit_accounts.php<?php echo '?id='.$id; ?>" class="btn btn-success"><i class="icon-pencil icon-large"></i></a>
</tr>
<?php } ?>
</tbody>
</table>
When I press edit, all information is there and After I click Update the error will show(as you can see in the picture) It's already getting the ID because it will not be show the information if not. And it does not save my update, I change the information but after click the button the information was still the same.
Information
Try this,
Replace :
$query=mysqli_query($dbcon,"select * from users_tbl where id
='$get_id'")or die(mysqli_error());
to
$query=mysqli_query($dbcon,"select * from users_tbl where id
=$get_id")or die(mysqli_error());
Remove the single quotes. has it is not replacing as its value.
Please let me know if this works for you.
you should check, does it return result or no.
This error is possible if you do not have proper ID in your DB.
$query=mysqli_query($dbcon,"select * from users_tbl where id ='$get_id'")or die(mysqli_error());
if (!($row=mysqli_fetch_array($query))) {
echo "Can not find user";
exit();
}
$id=$row['id'];
PS: spend time to learn what's prepared statements. And do not use way you passed arguments to SQL query. In this case it's very easy to do SQL Injection.
Any ideas what I'm doing wrong here? I'm getting the getID back fine as it's displaying when I echo on page but nothing else is getting set from database that I'm requesting.
I have tried a few things but cannot seem to crack it; I think maybe it might be bad markup from my side with the actual select query and how I put in the getID but might be wrong.
I've also added a foreach to list products, that might be wrong as well.
PHP / HTML
include('includes/config.php');
include('header.php');
include('functions.php');
$getID = $_GET['id'];
// Connect to the database
$mysqli = new mysqli(DATABASE_HOST, DATABASE_USER, DATABASE_PASS, DATABASE_NAME);
// output any connection error
if ($mysqli->connect_error) {
die('Error : ('.$mysqli->connect_errno .') '. $mysqli->connect_error);
}
// the query
$query = "SELECT i.*
FROM invoices as i
JOIN customers as c ON c.invoice = ".$getID."
JOIN invoice_items as p ON p.invoice = ".$getID."
ORDER BY i.invoice";
// mysqli select query
$results = $mysqli->query($query);
// mysqli select query
if($results) {
$customer_name = $row['customer_name']; // customer name
$customer_email = $row['customer_email']; // customer email
$customer_address_1 = $row['customer_address_1']; // customer address
$customer_address_2 = $row['customer_address_2']; // customer address
$customer_town = $row['customer_town']; // customer town
$customer_county = $row['customer_county']; // customer county
$customer_postcode = $row['customer_postcode']; // customer postcode
$customer_phone = $row['customer_phone']; // customer phone number
//shipping
$customer_name_ship = $row['customer_name_ship']; // customer name (shipping)
$customer_address_1_ship = $row['customer_address_1_ship']; // customer address (shipping)
$customer_address_2_ship = $row['customer_address_2_ship']; // customer address (shipping)
$customer_town_ship = $row['customer_town_ship']; // customer town (shipping)
$customer_county_ship = $row['customer_county_ship']; // customer county (shipping)
$customer_postcode_ship = $row['customer_postcode_ship']; // customer postcode (shipping)
// invoice details
$invoice_number = $row['invoice_id']; // invoice number
$invoice_date = $row['invoice_date']; // invoice date
$invoice_due_date = $row['invoice_due_date']; // invoice due date
$invoice_subtotal = $row['invoice_subtotal']; // invoice sub-total
$invoice_shipping = $row['invoice_shipping']; // invoice shipping amount
$invoice_discount = $row['invoice_discount']; // invoice discount
$invoice_vat = $row['invoice_vat']; // invoice vat
$invoice_total = $row['invoice_total']; // invoice total
$invoice_notes = $row['invoice_notes']; // Invoice notes
$invoice_status = $row['invoice_status']; // Invoice status
}
?>
<h1>Edit Invoice (<?php echo $getID; ?>)</h1>
<hr>
<div id="response" class="alert alert-success" style="display:none;">
×
<div class="message"></div>
</div>
<form method="post" id="create_invoice">
<input type="hidden" name="action" value="create_invoice">
<div class="row">
<div class="col-xs-5">
<h1>
<img src="<?php echo COMPANY_LOGO ?>" class="img-responsive">
</h1>
</div>
<div class="col-xs-7 text-right">
<div class="row">
<div class="col-xs-9">
<h1>INVOICE</h1>
</div>
<div class="col-xs-3">
<select name="invoice_status" id="invoice_status" class="form-control">
<option value="open" <?php if($invoice_status == "open"){?>selected<?php } ?>>Open</option>
<option value="paid" <?php if($invoice_status == "paid"){?>selected<?php } ?>>Paid</option>
</select>
</div>
</div>
<div class="col-xs-4 no-padding-right">
<div class="form-group">
<div class="input-group date" id="invoice_date">
<input type="text" class="form-control required" name="invoice_date" placeholder="Select invoice date" data-date-format="<?php echo DATE_FORMAT ?>" value="<?php echo $invoice_date; ?>" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
<div class="col-xs-4">
<div class="form-group">
<div class="input-group date" id="invoice_due_date">
<input type="text" class="form-control required" name="invoice_due_date" placeholder="Select due date" data-date-format="<?php echo DATE_FORMAT ?>" value="<?php echo $invoice_due_date; ?>" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
<div class="input-group col-xs-4 float-right">
<span class="input-group-addon">#<?php echo INVOICE_PREFIX ?></span>
<input type="text" name="invoice_id" id="invoice_id" class="form-control required" placeholder="Invoice Number" aria-describedby="sizing-addon1" value="<?php echo $getID; ?>">
</div>
</div>
</div>
<div class="row">
<div class="col-xs-6">
<div class="panel panel-default">
<div class="panel-heading">
<h4>Customer Information</h4>
<div class="clear"></div>
</div>
<div class="panel-body form-group form-group-sm">
<div class="row">
<div class="col-xs-6">
<div class="form-group">
<input type="text" class="form-control margin-bottom copy-input required" name="customer_name" id="customer_name" placeholder="Enter name" tabindex="1" value="<?php echo $customer_name; ?>">
</div>
<div class="form-group">
<input type="text" class="form-control margin-bottom copy-input required" name="customer_address_1" id="customer_address_1" placeholder="Address 1" tabindex="3" value="<?php echo $customer_address_1; ?>">
</div>
<div class="form-group">
<input type="text" class="form-control margin-bottom copy-input required" name="customer_town" id="customer_town" placeholder="Town" tabindex="5" value="<?php echo $customer_town; ?>">
</div>
<div class="form-group no-margin-bottom">
<input type="text" class="form-control copy-input required" name="customer_postcode" id="customer_postcode" placeholder="Postcode" tabindex="7" value="<?php echo $customer_postcode; ?>">
</div>
</div>
<div class="col-xs-6">
<div class="input-group float-right margin-bottom">
<span class="input-group-addon">#</span>
<input type="email" class="form-control copy-input required" name="customer_email" id="customer_email" placeholder="E-mail address" aria-describedby="sizing-addon1" tabindex="2" value="<?php echo $customer_email; ?>">
</div>
<div class="form-group">
<input type="text" class="form-control margin-bottom copy-input" name="customer_address_2" id="customer_address_2" placeholder="Address 2" tabindex="4" value="<?php echo $customer_address_2; ?>">
</div>
<div class="form-group">
<input type="text" class="form-control margin-bottom copy-input required" name="customer_county" id="customer_county" placeholder="County" tabindex="6" value="<?php echo $customer_county; ?>">
</div>
<div class="form-group no-margin-bottom">
<input type="text" class="form-control required" name="customer_phone" id="invoice_phone" placeholder="Phone number" tabindex="8" value="<?php echo $customer_phone; ?>">
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-xs-6 text-right">
<div class="panel panel-default">
<div class="panel-heading">
<h4>Shipping Information</h4>
</div>
<div class="panel-body form-group form-group-sm">
<div class="row">
<div class="col-xs-6">
<div class="form-group">
<input type="text" class="form-control margin-bottom required" name="customer_name_ship" id="customer_name_ship" placeholder="Enter name" tabindex="9" value="<?php echo $customer_name_ship; ?>">
</div>
<div class="form-group">
<input type="text" class="form-control margin-bottom" name="customer_address_2_ship" id="customer_address_2_ship" placeholder="Address 2" tabindex="11" value="<?php echo $customer_address_2_ship; ?>">
</div>
<div class="form-group no-margin-bottom">
<input type="text" class="form-control required" name="customer_county_ship" id="customer_county_ship" placeholder="County" tabindex="13" value="<?php echo $customer_county_ship; ?>">
</div>
</div>
<div class="col-xs-6">
<div class="form-group">
<input type="text" class="form-control margin-bottom required" name="customer_address_1_ship" id="customer_address_1_ship" placeholder="Address 1" tabindex="10" value="<?php echo $customer_address_1_ship; ?>">
</div>
<div class="form-group">
<input type="text" class="form-control margin-bottom required" name="customer_town_ship" id="customer_town_ship" placeholder="Town" tabindex="12" value="<?php echo $customer_town_ship; ?>">
</div>
<div class="form-group no-margin-bottom">
<input type="text" class="form-control required" name="customer_postcode_ship" id="customer_postcode_ship" placeholder="Postcode" tabindex="14" value="<?php echo $customer_postcode_ship; ?>">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- / end client details section -->
<table class="table table-bordered" id="invoice_table">
<thead>
<tr>
<th width="500">
<h4><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Item</h4>
</th>
<th>
<h4>Qty</h4>
</th>
<th>
<h4>Price</h4>
</th>
<th width="300">
<h4>Discount</h4>
</th>
<th>
<h4>Sub Total</h4>
</th>
</tr>
</thead>
<tbody>
<?php
foreach($invoice_product as $key => $value) {
$item_product = $value;
// $item_description = $_POST['invoice_product_desc'][$key];
$item_qty = $row['invoice_product_qty'][$key];
$item_price = $row['invoice_product_price'][$key];
$item_discount = $row['invoice_product_discount'][$key];
$item_subtotal = $row['invoice_product_sub'][$key];
?>
<tr>
<td>
<div class="form-group form-group-sm no-margin-bottom">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
<input type="text" class="form-control form-group-sm item-input invoice_product" name="invoice_product[]" placeholder="Enter item title and / or description" value="<?php echo $item_product; ?>">
<p class="item-select">or select an item</p>
</div>
</td>
<td class="text-right">
<div class="form-group form-group-sm no-margin-bottom">
<input type="text" class="form-control calculate" name="invoice_product_qty[]" value="1" value="<?php echo $item_qty; ?>">
</div>
</td>
<td class="text-right">
<div class="input-group input-group-sm no-margin-bottom">
<span class="input-group-addon"><?php echo CURRENCY ?></span>
<input type="text" class="form-control calculate invoice_product_price required" name="invoice_product_price[]" aria-describedby="sizing-addon1" placeholder="0.00" value="<?php echo $item_price; ?>">
</div>
</td>
<td class="text-right">
<div class="form-group form-group-sm no-margin-bottom">
<input type="text" class="form-control calculate" name="invoice_product_discount[]" placeholder="Enter % or value (ex: 10% or 10.50)" value="<?php echo $item_discount; ?>">
</div>
</td>
<td class="text-right">
<div class="input-group input-group-sm">
<span class="input-group-addon"><?php echo CURRENCY ?></span>
<input type="text" class="form-control calculate-sub" name="invoice_product_sub[]" id="invoice_product_sub" value="0.00" aria-describedby="sizing-addon1" value="<?php echo $item_subtotal; ?>" disabled>
</div>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<div id="invoice_totals" class="padding-right row text-right">
<div class="col-xs-6">
<div class="input-group form-group-sm textarea no-margin-bottom">
<textarea class-"form-control" name="invoice_notes" placeholder="Please enter any order notes here." value="<?php echo $invoice_notes; ?>"></textarea>
</div>
</div>
<div class="col-xs-6 no-padding-right">
<div class="row">
<div class="col-xs-3 col-xs-offset-6">
<strong>Sub Total:</strong>
</div>
<div class="col-xs-3">
<?php echo CURRENCY ?><span class="invoice-sub-total"> <?php echo $invoice_subtotal; ?></span>
<input type="hidden" name="invoice_subtotal" id="invoice_subtotal" value="<?php echo $invoice_subtotal; ?>">
</div>
</div>
<div class="row">
<div class="col-xs-3 col-xs-offset-6">
<strong>Discount:</strong>
</div>
<div class="col-xs-3">
<?php echo CURRENCY ?><span class="invoice-discount"> <?php echo $invoice_discount; ?></span>
<input type="hidden" name="invoice_discount" id="invoice_discount" value="<?php echo $invoice_discount; ?>">
</div>
</div>
<div class="row">
<div class="col-xs-3 col-xs-offset-6">
<strong class="shipping">Shipping:</strong>
</div>
<div class="col-xs-3">
<div class="input-group input-group-sm">
<span class="input-group-addon"><?php echo CURRENCY ?></span>
<input type="text" class="form-control calculate shipping" name="invoice_shipping" aria-describedby="sizing-addon1" placeholder="0.00" value="<?php echo $invoice_shipping; ?>">
</div>
</div>
</div>
<?php if (ENABLE_VAT == true) { ?>
<div class="row">
<div class="col-xs-3 col-xs-offset-6">
<strong>TAX/VAT:</strong>
</div>
<div class="col-xs-3">
<?php echo CURRENCY ?><span class="invoice-vat" data-enable-vat="<?php echo ENABLE_VAT ?>" data-vat-rate="<?php echo VAT_RATE ?>" data-vat-method="<?php echo VAT_INCLUDED ?>">0.00</span>
<input type="hidden" name="invoice_vat" id="invoice_vat">
</div>
</div>
<?php } ?>
<div class="row">
<div class="col-xs-3 col-xs-offset-6">
<strong>Total:</strong>
</div>
<div class="col-xs-3">
<?php echo CURRENCY ?><span class="invoice-total"> <?php echo $invoice_total; ?></span>
<input type="hidden" name="invoice_total" id="invoice_total" value="<?php echo $invoice_total; ?>">
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12 margin-top btn-group">
<input type="submit" id="action_edit_invoice" class="btn btn-success float-right" value="Update Invoice" data-loading-text="Updating...">
</div>
</div>
</form>
<div id="insert" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Select an item</h4>
</div>
<div class="modal-body">
<?php popProductsList(); ?>
</div>
<div class="modal-footer">
<button type="button" data-dismiss="modal" class="btn btn-primary" id="selected">Add</button>
<button type="button" data-dismiss="modal" class="btn">Cancel</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<?php
include('footer.php');
?>
The JOINs in your query are a little strange with constants in your ON clauses
...
JOIN customers as c ON c.invoice = ".$getID."
JOIN invoice_items as p ON p.invoice = ".$getID."
...
You want this instead. Your ON clauses need to express a relationship between rows in your three tables. Putting constant values in those clauses defeats that. Instead use a WHERE clause to filter the correct invoice number.
SELECT something, something
FROM invoices as i
JOIN customers as c ON c.invoice = i.invoice
JOIN invoice_items as p ON p.invoice = i.invoice
WHERE i.invoice = ".$getID."
ORDER BY i.invoice
Secondly, are you sure you have a column called invoice in all three of these tables? Your code mentions a column called invoice_id later on. Is that, in fact, the name of your join column?
Thirdly, it looks like your php code expects columns from two of your three tables to appear in your result set. For example.
....
$customer_postcode_ship = $row['customer_postcode_ship'];
....
$invoice_number = $row['invoice_id'];
...
But you did SELECT c.* which only returns the columns from your customers table.
Pro tip: Avoid * in SELECT clauses. Instead, list out the columns you want. Do something like this:
SELECT customer_name, customer_email, customer_address_1, customer_address_2,
customer_town, customer_county, customer_postcode,
customer_phone, customer_name_ship, customer_address_1_ship,
customer_address_2_ship, customer_town_ship, customer_county_ship,
customer_postcode_ship,
invoice_id, invoice_date, invoice_due_date, invoice_subtotal,
invoice_shipping, invoice_discount, invoice_vat, invoice_total,
invoice_notes, invoice_status
FROM ...
I know this seems impossibly verbose. But it's worth the effort because it allows your php code to be resilient to changes in table structure. It also makes it clear to the programmer who debugs this which columns are available in the result set.
Fourthly, keep in mind that you will get a combinatorial explosion of rows here. You're filtering for just one invoice which is fine. Presumably each invoice relates to only one customer. That too is fine. But, your customer and invoice column values will be repeated once for each matching row from your invoice_items table.
Fifth: check for an error return from $mysqli->query($query);.
$results = $mysqli->query($query);
if (!$results) {
printf("Errormessage: %s\n", $mysqli->error);
} else {
/* process the resultset */
}
As you work with SQL, this stuff will eventually become second nature. Don't get overly annoyed at the complexity of doing it right!