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.
Related
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 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
I am new in PHP. My href modal doesn't work perfectly.
I am working on a database search with edit items function.
On initial load of the datatable, the edit anchor tag should return field values in
the modal form.
However it doesn't seem to work. When I clicked the icon it didn't do anything.
I am thinking maybe there is conflict between my search queries and div ids?
Here is my code:
My code for the search query:
$sql_result = mysql_query ($sql, $conn ) or die ( "Could not execute SQL
query" .$sql);
if (mysql_num_rows($sql_result)>0) {
while ($row = mysql_fetch_assoc($sql_result)) {
$project=$row['Project'];
$id=$row['ID'];
$discipline=$row['Discipline'];
$area_code=$row['Area_Code'];
$drawingnumber=$row['Drawing_Number'];
$documenttitle=$row['Document_Title'];
$approveddate=$row['Approved_Date'];
$revnumber=$row['Revision'];
$status=$row['Status'];
$transnumber=$row['Transmittal_No'];
//table row
<tr>
<td><?php echo $project; ?></td>
<td><?php echo $discipline; ?></td>
<td><?php echo $area_code ;?></td>
<td><?php echo $drawingnumber ;?></td>
<td><?php echo $documenttitle; ?></td>
<td><?php echo $approveddate; ?></td>
<td><?php echo $revnumber; ?></td>
<td><?php echo $status; ?></td>
<td><?php echo $transnumber; ?></td>
<td><?php echo $id; ?></td>
<div class='btn-group' role='group' aria-label='...'>
<td> <button type='button' class='btn btn-warning btn-sm'>Edit<span class='glyphicon glyphicon-edit' aria-hidden='true'></span></button></td>
</div>
</tr>
My href edit Modal:
<div id="edit<?php echo $id; ?>" class="modal fade" role="dialog">
<form method="post" class="form-horizontal" role="form">
<div class="modal-dialog modal-lg">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Edit Item</h4>
</div>
<div class="modal-body">
<input type="hidden" name="edit_item_id" value="<?php echo $id; ?>">
<div class="form-group">
<label class="control-label col-sm-2" for="discipline">Discipline:</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="discipline" name="discipline" value="<?php echo $id; ?>" required autofocus>
</div>
<label class="control-label col-sm-2" for="area_code">Area Code:</label>
<div class="col-sm-4">
<input type="text" readonly class="form-control" id="area_code" name="area_code" value="<?php echo $area_code;?>" required>
</div>
<label class="control-label col-sm-2" for="drawingnumber">Drawing Number:</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="drawingnumber" name="drawingnumber" value="<?php echo $drawingnumber; ?>" required >
</div>
<label class="control-label col-sm-2" for="documenttitle">Document Title:</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="documenttitle" name="documenttitle" value="<?php echo $documenttitle; ?>" required >
</div>
<label class="control-label col-sm-2" for="approveddate">Approved Date:</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="approveddate" name="approveddate" value="<?php echo $approveddate; ?>" required>
</div>
<label class="control-label col-sm-2" for="revnumber">Revision Number:</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="revnumber" name="revnumber" value="<?php echo $revnumber; ?>" required >
</div>
<label class="control-label col-sm-2" for="status">Status:</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="status" name="status" value="<?php echo $status; ?>" required >
</div>
<label class="control-label col-sm-2" for="transnumber">Transmittal Number:</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="transnumber" name="transnumber" value="<?php echo $transnumber; ?>" required >
</div>
</div>
</div>
</div>
</div>
</form>
</div>
When I update one of the user, It will update some of user's timein too.
It's updating but I don't know why the other user too.
If I edit the time out it will change the timeout too of the some users. Sorry for my bad english.
logs.php
<tbody>
<?php
$user_query=mysqli_query($dbcon,"SELECT * FROM user_logs_tbl where create_date >= date(now())")or die(mysqli_error($dbcon));
//$user_query=mysqli_query($dbcon,"SELECT * FROM user_logs_tbl")or die(mysqli_error($dbcon));
while($row=mysqli_fetch_array($user_query)){
$ids = isset($_row['id']) ? $_row['id'] : '';
$_SESSION=$id=$row['user_id'];
$user_query2=mysqli_query($dbcon,"SELECT * FROM users_tbl where id='$id'")or die(mysqli_error($dbcon));
$row2= mysqli_fetch_array($user_query2);?>
<tr class="del<?php echo $ids ?>">
<td>
<?php echo $row['id']; ?>
</td>
<td>
<?php echo $row2['firstname']." ".$row2['middlename']." ".$row2['lastname']; ?>
</td>
<td>
<?php $course= $row['create_date'];
if($course == '') {
echo "N/A";
} else {
echo $course;
}
?>
</td>
<td>
<?php echo $tayming=$row['time_in']; ?>
</td>
<td>
<?php $yr_lvl=$row['time_out'];
if($yr_lvl == '') {
?>
<a rel="tooltip" title="Timeout" id="<?php echo $id; ?>" href="#timeout<?php echo $id; ?>" data-toggle="modal" class="btn btn-info"><i class="icon-minus icon-large"></i> Manual Time-Out</a>
<?php include('modal_time_user.php');
} else {
echo $yr_lvl;
}
?>
</td>
<td>
<?php
$d=mktime(9, 06);
$nice=date("h:i", $d);
if($tayming >= $nice) {
echo "You're Late! Bro!";
} else {
echo "Very Good!";
}
?>
</td>
<td>
<a rel="tooltip" title="Edit" id="<?php echo $id; ?>" href="#edit<?php echo $id; ?>" data-toggle="modal" class="btn btn-success"><i class="icon-pencil icon-large"></i> Edit</a>
<?php include('modal_edit_time.php'); ?>
</td>
<?php include('toolttip_edit_delete.php'); ?>
</tr>
<?php } ?>
</tbody>
this is the modal where if you click the button edit
modal_edit_time.php
<div id="edit<?php echo $id; ?>" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-body">
<div class="alert alert-info"><strong>Manual Time-In</strong></div>
<form class="form-horizontal" method="post">
<div class="control-group">
<label class="control-label" style="margin-left:29%;" for="inputEmail">Employee:</label>
<div class="controls">
<?php $wiw=mysqli_query($dbcon,"SELECT * FROM users_tbl where id='$id'");
$row2= mysqli_fetch_array($wiw);?>
<input type="hidden" id="inputEmail" name="id" value="<?php echo $row['user_id']; ?>" required>
<input type="text" name="userid" value="<?php echo $row2['firstname']." ".$row2['middlename']." ". $row2['lastname'];?>" readonly>
</div>
</div>
<div class="control-group">
<label class="control-label" style="margin-left:29%;" for="inputEmail">Date:</label>
<div class="controls">
<input type="date" id="inputEmail" value="<?php echo $row['create_date'];?>" name="create_date" placeholder="Date" required>
</div>
</div>
<div class="control-group">
<label class="control-label" style="margin-left:29%;" for="inputEmail">Time-In:</label>
<div class="controls">
<input type="time" id="inputEmail" value="<?php echo $row['time_in'];?>" name="timein" placeholder="Time" required>
</div>
</div>
<div class="control-group">
<label class="control-label" style="margin-left:29%;" for="inputEmail">Time-Out:</label>
<div class="controls">
<input type="time" id="inputEmail" value="<?php echo $row['time_out'];?>" name="timeout" placeholder="Time" required>
</div>
</div>
<div class="control-group">
<div class="controls">
<button name="edit" type="submit" class="btn btn-success"><i class="icon-save icon-large"></i> Save</button>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true"><i class="icon-remove icon-large"></i> Close</button>
</div>
</div>
<?php echo $id;
if (isset($_POST['edit'])){
$userid=$_POST['id'];
$timein=$_POST['timein'];
$timeout=$_POST['timeout'];
$create_date=$_POST['create_date'];
mysqli_query($dbcon,"UPDATE user_logs_tbl set time_in='$timein',time_out = '$timeout',create_date ='$create_date' where id='$id'")or die(mysqli_error($dbcon));
$yourURL="logs.php";
echo ("<script>location.href='$yourURL'</script>");
}
?>
Web interface:
Database :
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.