Jump to content

DanEthical

Members
  • Content Count

    68
  • Joined

  • Last visited

Everything posted by DanEthical

  1. hahaha Yep, this deserves Best Answer LOL, silly Irish boy here. Well, learnt something new. Thanks again.
  2. Got it. You guys are awesome. On submitting the form to add a new Maintenance Request, I have added an extra row for username. This tells the request who is logged in and what data to display. $sql = "INSERT INTO `maintenance_requests`(`driver_name`, `driver_email`, `fleet_number`, `speedo_reading`, `submit_date`, `issue_name`, `issue_description`, `issue_status`, `issue_priority`,`username`) VALUES ('".$driver_name."','".$driver_email."', '".$fleet_number."','".$speedo_reading."','".$submit_date."','".$issue_name."', '".$issue_description."', 'Open', 'Medium','".$username."')"; $link->query($sql) or die("Cannot Insert");//update or error } Then, displaying the data: $sql = "SELECT issue_id, driver_name, submit_date, fleet_number, issue_name, issue_description, issue_priority, issue_status FROM maintenance_requests WHERE username = '" . $_SESSION['username'] . "'"; // CREATE THE QUERY STATEMENT ITSELF BY ITSELF! $stmt = $link->prepare($sql); if(!$stmt) { // YOU NEED TO HANDLE THE POSSIBILITY OF FAILURE HERE ECHO 'PREPARE STATEMENT FAILED'; EXIT(); } ELSE { // YOU NEED A BIND STATEMENT HERE TO ASSIGN A VALUE TO THAT ? PARAMETER. if (!$stmt->execute()) { // HANDLE FAILURE OF THE EXECUTE HERE ECHO 'EXECUTE STATEMENT FAILED'; EXIT(); } ELSE { $stmt->bind_result($issue_id, $driver_name, $submit_date, $fleet_number, $issue_name, $issue_description, $issue_priority, $issue_status); while($stmt->fetch()) { $code=<<<heredocs <tr class="odd gradeX"> <td class="text-center">$issue_id</td> <td class="text-center">$driver_name</td> <td class="text-center">$submit_date</td> <td class="text-center">$fleet_number</td> <td class="text-center">$issue_name</td> <td class="text-center">$issue_description</td> <td class="text-center">$issue_priority</td> heredocs; echo $code; if($issue_status == "Pending") { echo "<td class='text-center warning'>$issue_status</td>"; } else if($issue_status == "Open") { echo "<td class='text-center danger'>$issue_status</td>"; } else if($issue_status == "Repaired") { echo "<td class='text-center success'>$issue_status</td>"; } echo '</tr>'; } } } ?> WHERE username = '" . $_SESSION['username'] . "'"; Is what was needed. I have logged in as two different users and it only displays the data they have submitted. Thank you all so much. Major obstacle overcome.
  3. The username is tied to the logged in user. $username is in a session in the users table.
  4. No, username is not in this table. I am trying to get the data that username has submitted. I am presuming that having $_SESSION['username'] will help identify what user submitted it? Sure. Here is the whole file including the rewritten code from ginerjm: <?php require_once('templates/header.php'); require_once('templates/sidebar.php'); ?> <div id="page-wrapper" > <div id="page-inner"> <div class="row"> <div class="col-md-12"> <h2><i class="fa fa-wrench"></i> Maintenance Requests </h2> <h5>Issues are dealt with in priority order and are removed from the system three months after repair. </h5> </div> </div> <!-- /. ROW --> <hr /> <div class="row"> <div class="col-md-12"> <!-- Advanced Tables --> <div class="panel panel-default"> <div class="panel-heading"> <i class="fa fa-info"></i> Listed below are the Maintenance Requests you have submitted and their current status. </div> <div class="panel-body"> <div class="table-responsive"> <table class="table table-striped table-bordered table-hover" id="bookings_table"> <thead> <tr> <th class="text-center">Issue ID</th> <th class="text-center">Driver Name</th> <th class="text-center">Date Submitted</th> <th class="text-center">Fleet Number</th> <th class="text-center">Issue</th> <th class="text-center">Description</th> <th class="text-center">Priority</th> <th class="text-center">Status</th> </tr> </thead> <tbody> <?php $check = isset($_SESSION['username']); // WHAT IS THE POINT OF THE ABOVE STATEMENT IF YOU NEVER ANALYZE THE RESULT? $sql = "SELECT issue_id, driver_name, submit_date, fleet_number, issue_name, issue_description, issue_priority, issue_status FROM maintenance_requests WHERE username = ?"; // CREATE THE QUERY STATEMENT ITSELF BY ITSELF! $stmt = $link->prepare($sql); if(!$stmt) { // YOU NEED TO HANDLE THE POSSIBILITY OF FAILURE HERE ECHO 'PREPARE STATEMENT FAILED'; EXIT(); } ELSE { // YOU NEED A BIND STATEMENT HERE TO ASSIGN A VALUE TO THAT ? PARAMETER. if (!$stmt->execute()) { // HANDLE FAILURE OF THE EXECUTE HERE ECHO 'EXECUTE STATEMENT FAILED'; EXIT(); } ELSE { $stmt->bind_result($issue_id, $driver_name, $submit_date, $fleet_number, $issue_name, $issue_description, $issue_priority, $issue_status); while($stmt->fetch()) { $code=<<<heredocs <tr class="odd gradeX"> <td class="text-center">$issue_id</td> <td class="text-center">$driver_name</td> <td class="text-center">$submit_date</td> <td class="text-center">$fleet_number</td> <td class="text-center">$issue_name</td> <td class="text-center">$issue_description</td> <td class="text-center">$issue_priority</td> heredocs; echo $code; if($issue_status == "Pending") { echo "<td class='text-center warning'>$issue_status</td>"; } else if($issue_status == "Open") { echo "<td class='text-center danger'>$issue_status</td>"; } else if($issue_status == "Repaired") { echo "<td class='text-center success'>$issue_status</td>"; } echo '</tr>'; } } } ?> </tbody> </table> <a href="submit-request.php"><button class="btn-default">New Request</button></a> </div> </div> </div> <hr> <!--End Advanced Tables --> </div> </div> </div> <!-- /. ROW --> </div> <!-- /. PAGE INNER --> </div> <!-- /. PAGE WRAPPER --> </div> <!-- /. WRAPPER --> <?php require_once('templates/footer.php'); ?> Thanks guys.
  5. Thank you so much for this and the explanation. Means a lot. I have put it in and it says "PREPARED STATEMENT FAILED".
  6. I have even changed it to use the OOP style statement from here: http://php.net/manual/en/mysqli.prepare.php Still the same.
  7. Yep, it's on all pages from header.php
  8. That is bloody strange. I have echo $_SESSION['username']; in the header and in index.php and they work. This page has everything that index.php has and the same header.php required to it and it is not showing? EDIT It shows the username if placed outside of the sql statement. So obviously there is an issue with the code.
  9. I know I am doing it wrong but for the life of me can't figure out the correct way. Searched google etc and anything I find that is even close to it doesn't work. I am checking the username as was suggested on another website (can't even find that now lol) because I am trying to display information that the logged in user submitted and only display that specific information and not show that user information that was submitted by another user.
  10. Ok. Have done this. Still same result: <?php $check = isset($username); if($stmt = $link -> prepare("SELECT issue_id, driver_name, submit_date, fleet_number, issue_name, issue_description, issue_priority, issue_status FROM maintenance_requests WHERE username=?")) { $stmt->bind_param('s',$username); $stmt -> execute(); $stmt -> bind_result($issue_id, $driver_name, $submit_date, $fleet_number, $issue_name, $issue_description, $issue_priority, $issue_status); while($stmt->fetch()) { ?>
  11. Thanks Barand. I have added $username to the bind_result and still showing blank.
  12. Hi guys, I am trying to display data to a user who submitted it. So, user A submits data to the db and also user B. I want it so that user A cannot see user B's data but only the data they have submitted. Hope that makes sense. Here is the code along with the table of data to be displayed. <div class="panel-body"> <div class="table-responsive"> <table class="table table-striped table-bordered table-hover" id="bookings_table"> <thead> <tr> <th class="text-center">Issue ID</th> <th class="text-center">Driver Name</th> <th class="text-center">Date Submitted</th> <th class="text-center">Fleet Number</th> <th class="text-center">Issue</th> <th class="text-center">Description</th> <th class="text-center">Priority</th> <th class="text-center">Status</th> </tr> </thead> <tbody> <?php $check = isset($_SESSION['username']); if($stmt = $link -> prepare("SELECT issue_id, driver_name, submit_date, fleet_number, issue_name, issue_description, issue_priority, issue_status FROM maintenance_requests WHERE username = ?")) { $stmt -> execute(); $stmt -> bind_result($issue_id, $driver_name, $submit_date, $fleet_number, $issue_name, $issue_description, $issue_priority, $issue_status); while($stmt->fetch()) { ?> <tr class="odd gradeX"> <td class="text-center"><?php echo $issue_id; ?></td> <td class="text-center"><?php echo $driver_name; ?></td> <td class="text-center"><?php echo $submit_date; ?></td> <td class="text-center"><?php echo $fleet_number; ?></td> <td class="text-center"><?php echo $issue_name; ?></td> <td class="text-center"><?php echo $issue_description; ?></td> <td class="text-center"><?php echo $issue_priority; ?></td> <?php if($issue_status == "Pending") { ?> <td class="text-center warning"><?php echo $issue_status;?></td> <?php }else if($issue_status == "Open"){ ?> <td class="text-center danger"><?php echo $issue_status; ?></td> <?php }else if($issue_status == "Repaired"){ ?> <td class="text-center success"><?php echo $issue_status ;} ?></td> </tr> <?php } $stmt -> close(); } mysqli_close($link); ?> If I remove the WHERE clause, it displays data from both users. Placing the WHERE clause shows no data. Can someone have a look and see where I am going wrong and maybe point me in the right direction? Many thanks in advance.
  13. <select class="form-control" name="maintreq[<?php echo $issue_id; ?>][issue_priority]"> <?php echo '<option value="'.$issue_priority.'">'.$issue_priority.'</option>'; ?> <option value="High">High</option> <option value="Medium">Medium</option> <option value="Low">Low</option> </select> </td> <td class="text-center"> <select class="form-control" name="maintreq[<?php echo $issue_id; ?>][issue_status]"> <?php echo '<option value="'.$issue_status.'">'.$issue_status.'</option>'; ?> <option Value="Open">Open</option> <option Value="Pending">Pending</option> <option value="Repaired">Repaired</option> </select> That better? It works now though. Nothing getting deleted or anything and everything gets updated the way I want.
  14. Ok, did the following, which updates. However, if I update, for example, one dropdown for issue_priority, it updates in the DB but removes the others. if(isset($_POST['Update'])){//if the submit button is clicked // Loop through each issue foreach ($_POST['maintreq'] as $issueID => $issueArr) { // Prep statement $stmt = "UPDATE maintenance_requests SET issue_status = '".$issueArr['issue_status']."', issue_priority = '".$issueArr['issue_priority']."' WHERE issue_id = '".$issueID."'"; // Run it $link->query($stmt) or die("Cannot update");//update or error } }
  15. I am trying to update those particular fields only in MySQL. So, for example, the table is for vehicle issues. The mechanic logs in, looks at Maintenance Requests that are submitted by drivers. He fixes the changes the status of the issue from Open to Pending or Repaired using the values in the dropdown and also the priority of the issue to either High, Medium or Low using the values of that dropdown. Once the form is submitted, it updates the fields in the database issue_priority and issue_status to the values the mechanic selected in the form. But this is not happening. The hidden field is capturing the current value in the database and selecting the value in the dropdown that the database is valued to. This works.
  16. It is because each dropdown is updated individually or as a whole. If I don't have that there, submitting one dropdown value updates all. So I geussed having the GET id will allow for the form submission to just update the effected or chosen value.
  17. Hi all, Trying to update two rows in a MySQL table using MySQLi and PHP with values from a bootstrap dropdown. No errors or anything (have error reporting turned on), just nothing is updated in the database. Here is the update code (if anyone has a prepared version of it would love to have it). if(isset($_POST['Update'])){//if the submit button is clicked if(isset($_GET['issue_id']) && isset($_POST['issue_priority']) && isset($_POST['issue_status'])) { $sql="UPDATE maintenance_requests SET issue_status='$issue_status', issue_priority='$issue_priority' WHERE issue_id='".$_GET['issue_id']."'"; $link->query($sql) or die("Cannot update");//update or error } } ?> And here is the form: <form role="form" method="POST" action="" /> <table class="table table-striped table-bordered table-hover" id="bookings_table"> <thead> <tr> <th class="text-center">Issue ID</th> <th class="text-center">Driver Name</th> <th class="text-center">Date Submitted</th> <th class="text-center">Fleet Number</th> <th class="text-center">Issue</th> <th class="text-center">Description</th> <th class="text-center">Priority</th> <th class="text-center">Status</th> </tr> </thead> <tbody> <tr class="odd gradeX"> <td class="text-center"><?php echo $issue_id; ?></td> <td class="text-center"><?php echo $driver_name; ?></td> <td class="text-center"><?php echo $issue_date; ?></td> <td class="text-center"><?php echo $fleet_number; ?></td> <td class="text-center"><?php echo $issue_name; ?></td> <td class="text-center"><?php echo $issue_description; ?></td> <td class="text-center"> <select name="issue_priority"> <option value="" hidden="hidden"><?php echo $issue_priority; ?></option> <option value="High">High</option> <option value="Medium">Medium</option> <option value="Low">Low</option> </select> </td> <td class="text-center"> <select name="issue_status"> <option value="" hidden="hidden"><?php echo $issue_status; ?></option> <option Value="Open">Open</option> <option Value="Pending">Pending</option> <option value="Repaired">Repaired</option> </select> </td> </tr> </tbody> <?php } $stmt -> close(); } mysqli_close($link); ?> </table> <input type="submit" class="btn btn-default" name="Update" value="Update Issue"> </div> </form> Any help would be really appreciated. Have searched the forums and searched Google but nothing found. Thanks heaps.
  18. For anyone interested, I got this working, with the help of a mate, with the following: if(isset($_POST['calculate']) != ""){ class times_counter { private $hou = 0; private $min = 0; private $sec = 0; private $totaltime = '00:00:00'; public function __construct($times){ if(is_array($times)){ $length = sizeof($times); for($x=0; $x <= $length; $x++){ $split = explode(":", @$times[$x]); $this->hou += @$split[0]; $this->min += @$split[1]; $this->sec += @$split[2]; } $seconds = $this->sec % 60; $minutes = $this->sec / 60; $minutes = (integer)$minutes; $minutes += $this->min; $hours = $minutes / 60; $minutes = $minutes % 60; $hours = (integer)$hours; $hours += $this->hou % 24; $this->totaltime = $hours.":".$minutes.":".$seconds; } } public function get_total_time(){ return $this->totaltime; } } $times = array( $mondiff->format('%H:%I'), $tudiff->format('%H:%I'), $weddiff->format('%H:%I'), $thdiff->format('%H:%I'), $fridiff->format('%H:%I'), $satdiff->format('%H:%I'), $sundiff->format('%H:%I'), ); $counter = new times_counter($times); echo $counter->get_total_time();
  19. Hi folks, Thanks for the replies. Really appreciate it. Basically, I have the following (one for each day of the week), which gives a total hours worked each day, minus whatever period of time for breaks. It works fine and calculates the difference between the start time and end time and also subtracts the break period from the total. <?php if(isset($_POST['start_shift7']) && $_POST['end_shift7'] && $_POST['break7'] != "") { $datetime1 = new DateTime($_POST['start_shift7']); $datetime2 = new DateTime($_POST['end_shift7']); list($h, $m) = explode(":", $_POST['break7']); $break = new DateInterval("PT{$h}H{$m}M"); $sundiff = $datetime1->add($break)->diff($datetime2); ?> <input type="text" readonly class="form-control" name="sunday" value="<?php echo $sundiff->format('%H:%I'); ?>"> <?php } ?> Now, what I am trying to do, is get the totals from each day, add them together to get a total for the week. I am not very well educated and the Jargon gets me 90% of the time. My apologies for that.
  20. Hey all, I am trying to get the total number of hours from an array as follows: <?php if(isset($_POST['calculate']) != ""){ class times_counter { private $hou = 0; private $min = 0; private $sec = 0; private $totaltime = '00:00:00'; public function __construct($times){ if(is_array($times)){ $length = sizeof($times); for($x=0; $x <= $length; $x++){ $split = explode(":", @$times[$x]); $this->hou += @$split[0]; $this->min += @$split[1]; $this->sec += @$split[2]; } $seconds = $this->sec % 60; $minutes = $this->sec / 60; $minutes = (integer)$minutes; $minutes += $this->min; $hours = $minutes / 60; $minutes = $minutes % 60; $hours = (integer)$hours; $hours += $this->hou % 24; $this->totaltime = $hours.":".$minutes.":".$seconds; } } public function get_total_time(){ return $this->totaltime; } } $times = array( '02:00:00', '12:15:00' ); $counter = new times_counter($times); echo $counter->get_total_time(); ?> This works fine as is with times just placed inside the array. However, I need to get the times from an object, such as: $times = array( $time1, $time2 ); This will not work because it throws an error - Warning: explode() expects parameter 2 to be string, object given The warning is thrown from here: $split = explode(":", @$times[$x]); Is there a way for me to add all the hours to get a total of the hours? For example: $time1 = 12:00 $time2 = 12:00 Total Hours = 24:00 ,<- This is what I am after. Thanks in advance,
  21. You are a star. Now I get the add thingy and it works.
  22. Thanks mate. Have tried this. Obviously not correctly. The ADD part has me f**ked. I think because I haven't had decent Guinness since leaving Ireland is what has my brain fried. I appreciate the efforts in helping though, really do.
  23. Example #1 DateTime::sub() example Object oriented style <?php $date = new DateTime('2000-01-20'); $date->sub(new DateInterval('P10D')); echo $date->format('Y-m-d') . "\n"; ?> Procedural style <?php $date = date_create('2000-01-20'); date_sub($date, date_interval_create_from_date_string('10 days')); echo date_format($date, 'Y-m-d'); ?> From RTFM
  24. I tried what you suggested mate, and what others suggested and what PHP themselves even suggest. Nothing works for me. Only one getting pissed off here is you.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.