ianhaney
Members-
Posts
330 -
Joined
-
Last visited
-
Days Won
1
Everything posted by ianhaney
-
I have made the changes but can it be checked over as on the page, I have the description input field blank and the status is not pulled from the database and got the following error Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: parameter was not defined' in /home/sites/it-doneright.co.uk/public_html/admin/staff-tasks/update-staff-task.php:58 Stack trace: #0 /home/sites/it-doneright.co.uk/public_html/admin/staff-tasks/update-staff-task.php(58): PDOStatement->execute(Array) #1 /home/sites/it-doneright.co.uk/public_html/admin/staff-tasks/update-staff-task.php(96): emps_assigned_by_taskid() #2 {main} thrown in /home/sites/it-doneright.co.uk/public_html/admin/staff-tasks/update-staff-task.php on line 58 Below is the code on line 58 $stmt->execute(array('task_id' => $task_id)); Below is the whole code <?php ini_set('display_startup_errors',1); ini_set('display_errors',1); error_reporting(-1); ?> <? session_start(); if($_SESSION['user']==''){ header("Location:login.php"); }else{ include("config.php"); $sql=$dbh->prepare("SELECT * FROM employee WHERE emp_id=?"); $sql->execute(array($_SESSION['user'])); while($r=$sql->fetch()){ echo "<div class='home-content'>"; echo "<center><h2>Hello, ".$r['username']."</h2>"; echo "<a href='logout.php'>Log Out</a></center>"; echo "</div>"; } } ?> <?php $hostname=''; $username=''; $password=''; $db = new PDO("mysql:host=$hostname;dbname=",$username,$password); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // return the task which matches $_GET['task_id']; $sql=$dbh->prepare(" SELECT task_id description status FROM task WHERE task_id = ?"); $sql->execute(array($_GET['task_id'])); $sql->setFetchMode(PDO::FETCH_ASSOC); // fetch the row from the result $row = $sql->fetch(); function emps_assigned_by_taskid($db, $task_id) /******************************************* * function to list employees with checkboxes - checkbox is checked if they are assigned to the task ********************************************/ { $sql = "SELECT e.emp_id, e.emp_name, IF(a.emp_id IS NULL, 0, 1) as isAssigned FROM employee LEFT JOIN assignment a ON e.emp_id = a.emp_id WHERE a.task_id = ?"; $stmt = $db->prepare($sql); $stmt->execute(array('task_id' => $task_id)); $emps=''; foreach($stmt->fetchAll() as $row) { // if isAssigned is set to 1 then set the checked attribute, otherwise leave blank $checked = $row['isAssigned'] == 1 ? ' checked="checked" ' : ''; $emps .= "<input type='checkbox' name='emp_id[]' value='{$row['emp_id']}'{$checked}> {$row['emp_name']}<br>"; } return $emps; } ?> <html> <head> <title>Update Task</title> </head> <body> <div id='title'> <h1>Edit Task</h1> <form method="post" action="update-staff-task.php"> <fieldset> <legend>Task</legend> <div class='label'><label for='descrip'>Description</label></div> <input type="text" name="descrip" id="descrip" size="50" value="<?php echo $row['description']; ?>" /> <br> <br> <div class='label'><label for='status'>Status</label></div> <select name='status' id='status'> <option value='0'>Not started</option> <option value='1'>In progress</option> <option value='2'>Completed</option> </select> </fieldset> <br> <fieldset> <legend>Assign to</legend> <?= emps_assigned_by_taskid($db, $_GET['task_id']) ?> </fieldset> <input type="submit" name="btnSubmit" value="Update"> </form> </div> </body> </html>
-
Hi I have a update, I have managed to get the form displaying but got a error in the description input field The error is below <br /><b>Notice</b>: Undefined variable: row in <b>/home/sites/it-doneright.co.uk/public_html/admin/staff-tasks/update-staff-task.php</b> on line <b>76</b><br /> The code I have now is below <?php ini_set('display_startup_errors',1); ini_set('display_errors',1); error_reporting(-1); ?> <? session_start(); if($_SESSION['user']==''){ header("Location:login.php"); }else{ include("config.php"); $sql=$dbh->prepare("SELECT * FROM employee WHERE emp_id=?"); $sql->execute(array($_SESSION['user'])); while($r=$sql->fetch()){ echo "<div class='home-content'>"; echo "<center><h2>Hello, ".$r['username']."</h2>"; echo "<a href='logout.php'>Log Out</a></center>"; echo "</div>"; } } ?> <?php $hostname=''; $username=''; $password=''; $db = new PDO("mysql:host=$hostname;dbname=",$username,$password); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sql=$dbh->prepare("SELECT e.emp_id , t.task_id , t.description , t.status FROM employee e JOIN assignment a ON e.emp_id = a.emp_id JOIN task t ON a.task_id = t.task_id WHERE e.emp_id = ?"); $sql->execute(array($_SESSION['user'])); $sql->setFetchMode(PDO::FETCH_ASSOC); function emps($db) /******************************************* * function to list employees with checkboxes ********************************************/ { $sql = "SELECT emp_id, emp_name FROM employee ORDER BY emp_name"; $emps=''; foreach($db->query($sql) as $row) { $emps .= "<input type='checkbox' name='emp_id[]' value='{$row['emp_id']}'> {$row['emp_name']}<br>"; } return $emps; } ?> <html> <head> <title>Update Task</title> </head> <body> <div id='title'> <h1>Edit Task</h1> <form method="post" action="update-staff-task.php"> <fieldset> <legend>Task</legend> <div class='label'><label for='descrip'>Description</label></div> <input type="text" name="descrip" id="descrip" size="50" value="<?php echo $row['description']; ?>" /> <br> <div class='label'><label for='status'>Status</label></div> <select name='status' id='status'> <option value='0'>Not started</option> <option value='1'>In progress</option> <option value='2'>Completed</option> </select> </fieldset> <br> <fieldset> <legend>Assign to</legend> <?= emps($db) ?> </fieldset> <input type="submit" name="btnSubmit" value="Update"> </form> </div> </body> </html> Can someone take a look at my code please and see where I am going wrong, thank you
-
Hi Still trying to work out the update task issue but am still stuck The page does not show any errors but does not show any data from the database tables to update I have the following code <?php ini_set('display_startup_errors',1); ini_set('display_errors',1); error_reporting(-1); ?> <? session_start(); if($_SESSION['user']==''){ header("Location:login.php"); }else{ include("config.php"); $sql=$dbh->prepare("SELECT * FROM employee WHERE emp_id=?"); $sql->execute(array($_SESSION['user'])); while($r=$sql->fetch()){ echo "<div class='home-content'>"; echo "<center><h2>Hello, ".$r['username']."</h2>"; echo "<a href='logout.php'>Log Out</a></center>"; echo "</div>"; } } ?> <?php include("config.php"); $sql=$dbh->prepare("SELECT e.emp_id , t.task_id , t.description , t.status FROM employee e JOIN assignment a ON e.emp_id = a.emp_id JOIN task t ON a.task_id = t.task_id WHERE e.emp_id = ?"); $sql->execute(array($_SESSION['user'])); // were any rows found? if ($row = $sql->fetchObject()) { ?> <html> <head> <title>Add Task</title> </head> <body> <div id='title'> <h1>Edit Task</h1> <form method="post" action="update-staff-task.php"> <fieldset> <legend>Task</legend> <div class='label'><label for='descrip'>Description</label></div> <input type="text" name="descrip" id="descrip" size="50" value="<?php echo $row['description']; ?>" /> <br> <div class='label'><label for='status'>Status</label></div> <select name='status' id='status'> <option value='0'>Not started</option> <option value='1'>In progress</option> <option value='2'>Completed</option> </select> </fieldset> <br> <fieldset> <legend>Assign to</legend> <?= emps($db) ?> </fieldset> <input type="submit" name="btnSubmit" value="Submit"> <?php } ?> </form> </div> </body> </html> <?php function emps($db) /******************************************* * function to list employees with checkboxes ********************************************/ { $sql = "SELECT emp_id, emp_name FROM employee ORDER BY emp_name"; $emps=''; foreach($db->query($sql) as $row) { $emps .= "<input type='checkbox' name='emp_id[]' value='{$row['emp_id']}'> {$row['emp_name']}<br>"; } return $emps; } ?>
-
Sorry am trying to get my head around this, I have got the correct task_id in the url to update as the url looks like the following http://www.it-doneright.co.uk/admin/staff-tasks/update-staff-task.php?task_id=3 but in the description input field, I have <br /><b>Notice</b>: Undefined variable: row in <b>/home/sites/it-doneright.co.uk/public_html/admin/staff-tasks/update-staff-task.php</b> on line <b>70</b><br /> then is not pulling any data out for example the checkboxes and status is not pulled from the database which is where I am stuck as unsure how to do that part
-
Ok so to do that, would it be using SELECT query and a WHERE clause to get the correct task_id to update
-
Got stuck again trying to work the UPDATE form out, I got the following so far <?php ini_set('display_startup_errors',1); ini_set('display_errors',1); error_reporting(-1); ?> <?php $hostname='localhost'; $username=''; $password=''; ?> <?php $db = new PDO("mysql:host=$hostname;dbname=DBNAME",$username,$password); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); if ($_SERVER['REQUEST_METHOD']=='POST') { // was data sent if ($_POST['descrip'] != '') { try { $db->beginTransaction(); $sql = "UPDATE task (description, status) VALUES (?,?) WHERE task_id = $task_id"; $stmt = $db->prepare($sql); $stmt->execute(array($_POST['descrip'], $_POST['status'])); $task_id = $db->lastInsertId(); // get the id of new task // now insert employees assigned to the task $sql = "UPDATE assignment(task_id, emp_id) VALUES (?,?) WHERE task_id = $task_id"; $stmt = $db->prepare($sql); foreach ($_POST['emp_id'] as $emp) { $stmt->execute(array($task_id, $emp)); } $db->commit(); } catch (PDOException $e) { $db->rollBack(); die($e->getMessage()); } } } function emps($db) /******************************************* * function to list employees with checkboxes ********************************************/ { $sql = "SELECT emp_id, emp_name FROM employee ORDER BY emp_name"; $emps=''; foreach($db->query($sql) as $row) { $emps .= "<input type='checkbox' name='emp_id[]' value='{$row['emp_id']}'> {$row['emp_name']}<br>"; } return $emps; } ?> <html> <head> <title>Add Task</title> </head> <body> <div id='title'> <h1>Add Task</h1> <form method="post" action="update-staff-task.php"> <fieldset> <legend>Task</legend> <div class='label'><label for='descrip'>Description</label></div> <input type="text" name="descrip" id="descrip" size="50" value="<?php echo $row['description']; ?>" /> <br> <div class='label'><label for='status'>Status</label></div> <select name='status' id='status'> <option value='0'>Not started</option> <option value='1'>In progress</option> <option value='2'>Completed</option> </select> </fieldset> <br> <fieldset> <legend>Assign to</legend> <?= emps($db) ?> </fieldset> <input type="submit" name="btnSubmit" value="Submit"> </form> </div> </body> </html> I know or think I need to put in a while loop or something somewhere just after the form I think and need the SELECT query as well but unsure where it all goes, sorry
-
Thank you so much, works perfect I can now create the edit task form, am guessing will be similar to the form for inserting but will be UPDATE instead of INSERT for the query
-
Hi Barand I put that code in but in dreamweaver, it says there is syntax error with the following lines $stmt->execute([$_POST['descrip'], $_POST['status']]); $stmt->execute([$task_id, $emp]);
-
I tried the following code but just got a error $sql = "INSERT INTO task (description,status) SELECT task_id FROM task; INSERT INTO assignment (task_id) SELECT task_id FROM task"; ERROR: Could not able to execute INSERT INTO task (description,status) VALUES ('replace battery test 4', 'In Process') SELECT task_id FROM task; INSERT INTO assignment (task_id) SELECT task_id FROM task. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT task_id FROM task; INSERT INTO assignment (task_id) SELECT task_id FROM t' at line 1
-
Sorry got bit lost, the task_id is auto increment and primary key would something like the following work? INSERT INTO tbl(field, field) VALUES(val, val); INSERT INTO tbl2(field2, field2) VALUES(val2, val2);
-
would I need to do a INSERT then SELECT in the same query to get the task_id from the task table to show in the assign table on insert Hope that makes sense
-
Sorry I was looking to see how to delete the other one or this one
-
Sorry was my fault, the database credentials were wrong so corrected them now and is inserting the data to the task table now but unsure how to add the data to a second table as well as my first table is assignment that has assign_id, emp_id and task_id the second table is employee which has emp_id, username, password and the third is task table which has task_id, description, status and they are all joined but unsure how to get the task id added to assignment table as well
-
Sorry was my fault, the database credentials were wrong so corrected them now and is inserting the data to the task table now but unsure how to add the data to a second table as well as my first table is assignment that has assign_id, emp_id and task_id the second table is employee which has emp_id, username, password and the third is task table which has task_id, description, status and they are all joined but unsure how to get the task id added to assignment table as well
-
Within the code I have, I have added the database credentials but removed them in my post for security reasons
-
Hi I have built the form and a php file to insert the data but got the following issue ERROR: Could not able to execute INSERT INTO task (description, status) VALUES ('replace battery test', 'In Process'). Table 'cl10-itdonerig.task' doesn't exist Below is the code I have for the form and insert data php file form php file <?php ini_set('display_startup_errors',1); ini_set('display_errors',1); error_reporting(-1); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Add Staff Task</title> <link rel="stylesheet" type="text/css" media="screen" href="css/styles.css" /> </head> <body> <div id="logo"> <img src="images/logo/it-done-right.jpg" alt="" title=""> </div> <? session_start(); if($_SESSION['user']==''){ header("Location:index.php"); }else{ include("config.php"); $sql=$dbh->prepare("SELECT * FROM users WHERE id=?"); $sql->execute(array($_SESSION['user'])); while($r=$sql->fetch()){ echo "<div class='home-content'>"; echo "<center><h2>Hello, ".$r['username']."</h2>"; echo "<a href='logout.php'>Log Out</a></center>"; echo "</div>"; } } ?> <br> <form action="insert-staff-task.php" method="post" class="basic-grey"> <label for="description">Description:</label> <input type="text" name="description" id="description"> <br><br> <label for="employee">Assign to Employee:</label> <select name="employee"> <option value="Ian Haney (emp id: 2)">Ian Haney</option> <option value="Phil Roskams emp id: 3)">Phil Roskams</option> </select> <br><br> <label for="status">Status:</label> <select name="status"> <option value="In Process">In Process</option> <option value="Complete">Complete</option> </select> <br><br> <input type="submit" value="Add Records"> </form> </body> </html> insert data php file <?php ini_set('display_startup_errors',1); ini_set('display_errors',1); error_reporting(-1); ?> <?php /* Attempt MySQL server connection. Assuming you are running MySQL server with default setting (user 'root' with no password) */ $link = mysqli_connect("", "", "", ""); // Check connection if($link === false){ die("ERROR: Could not connect. " . mysqli_connect_error()); } // Escape user inputs for security $description = mysqli_real_escape_string($link, trim($_POST['description'])); $status = mysqli_real_escape_string($link, trim($_POST['status'])); // attempt insert query execution $sql = "INSERT INTO task (description, status) VALUES ('$description', '$status')"; if(mysqli_query($link, $sql)){ echo "Records added successfully."; } else{ echo "ERROR: Could not able to execute $sql. " . mysqli_error($link); } // close connection mysqli_close($link); ?>
-
Hi Barand Thank you so much, is working perfect I can build the admin form now to add the tasks and assign them to employees, hopefully will be straight forward to do if get stuck, is it ok to post
-
Hi I have altered the coding slightly and got no errors now but no results still? <?php ini_set('display_startup_errors',1); ini_set('display_errors',1); error_reporting(-1); ?> <!DOCTYPE html> <html> <head> <title>View Tasks</title> <link rel="stylesheet" type="text/css" media="screen" href="css/login-styles.css" /> </head> <body> <h2>View Tasks</h2> <? session_start(); if($_SESSION['user']==''){ header("Location:login.php"); }else{ include("config.php"); $sql=$dbh->prepare("SELECT * FROM employee WHERE emp_id=?"); $sql->execute(array($_SESSION['user'])); while($r=$sql->fetch()){ echo "<div class='home-content'>"; echo "<center><h2>Hello, ".$r['username']."</h2>"; echo "<a href='logout.php'>Log Out</a></center>"; echo "</div>"; } } ?> <?php include("config.php"); $sql=$dbh->prepare("SELECT e.emp_id , t.task_id , t.description , t.status FROM employee e JOIN assignment a ON e.emp_id = a.emp_id JOIN task t ON a.task_id = t.task_id WHERE e.emp_id = ?"); $sql->execute(array($_SESSION['user'])); { // display records if there are records to display //if ($sql->num_rows > 0) if ($sql->fetchColumn() > 0) { // display records in a table echo "<table>"; // set table headers echo "<tr> <th>Task ID</th> <th>Description</th> <th>Status</th> <th>Emp ID</th> <th>Status</th> <th colspan='1'>Actions</th> </tr>"; while ($row = $sql->fetchColumn()) { // set up a row for each record echo "<tr>"; echo "<td>" . $row->task_id . "</td>"; echo "<td>" . $row->description . "</td>"; echo "<td>" . $row->status . "</td>"; echo "<td>" . $row->emp_id . "</td>"; echo "<td>" . $row->status . "</td>"; echo "<td><a href='records.php?task_id=" . $row->task_id . "'>Edit</a></td>"; echo "</tr>"; } echo "</table>"; } // if there are no records in the database, display an alert message else { echo "No results to display!"; } } // show an error if there is an issue with the database query /*else { echo "Error: " . $mysqli->error; }*/ // close database connection $dbh = null; ?> </body> </html>
-
I currently have the following code <?php ini_set('display_startup_errors',1); ini_set('display_errors',1); error_reporting(-1); ?> <!DOCTYPE html> <html> <head> <title>View Tasks</title> <link rel="stylesheet" type="text/css" media="screen" href="css/login-styles.css" /> </head> <body> <h2>View Tasks</h2> <? session_start(); if($_SESSION['user']==''){ header("Location:login.php"); }else{ include("config.php"); $sql=$dbh->prepare("SELECT * FROM employee WHERE emp_id=?"); $sql->execute(array($_SESSION['user'])); while($r=$sql->fetch()){ echo "<div class='home-content'>"; echo "<center><h2>Hello, ".$r['username']."</h2>"; echo "<a href='logout.php'>Log Out</a></center>"; echo "</div>"; } } ?> <?php include("db-connect.php"); // get the records from the database if ($result = $mysqli->prepare("SELECT e.emp_id , t.task_id , t.description , t.status FROM employee e JOIN assignment a ON e.emp_id = a.emp_id JOIN task t ON a.task_id = t.task_id WHERE e.emp_id = ?")); $sql->execute(array($_SESSION['user'])); { // display records if there are records to display if ($result->num_rows > 0) { // display records in a table echo "<table>"; // set table headers echo "<tr> <th>Task ID</th> <th>Description</th> <th>Status</th> <th>Emp ID</th> <th>Status</th> <th colspan='1'>Actions</th> </tr>"; while ($row = $result->fetch_object()) { // set up a row for each record echo "<tr>"; echo "<td>" . $row->task_id . "</td>"; echo "<td>" . $row->description . "</td>"; echo "<td>" . $row->status . "</td>"; echo "<td>" . $row->emp_id . "</td>"; echo "<td>" . $row->status . "</td>"; echo "<td><a href='records.php?task_id=" . $row->task_id . "'>Edit</a></td>"; echo "</tr>"; } echo "</table>"; } // if there are no records in the database, display an alert message else { echo "No results to display!"; } } // show an error if there is an issue with the database query /*else { echo "Error: " . $mysqli->error; }*/ // close database connection $mysqli->close(); ?> </body> </html> sorry am bit lost what to change, is it this line if ($result = $mysqli->prepare("SELECT e.emp_id , t.task_id , t.description , t.status FROM employee e JOIN assignment a ON e.emp_id = a.emp_id JOIN task t ON a.task_id = t.task_id WHERE e.emp_id = ?")); $sql->execute(array($_SESSION['user']));
-
Yeah in there is assign id of 1, emp_id of 2 and task_id of 1
-
I thought it was cause the task was assigned to emp_id in the database but just changed it to 2 thinking the task would show cause emp_id 2 is signed in but still says 0 results
-
Sorry I didn't, I had that in already I changed it to prepare now and have no errors now but is displaying no results
-
Hmm def don't like something in my coding as got the following errors Warning: mysqli::query() [mysqli.query]: (42000/1064): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?' at line 9 in /home/sites/it-doneright.co.uk/public_html/admin/staff-tasks/view-employee-tasks.php on line 48 Notice: Trying to get property of non-object in /home/sites/it-doneright.co.uk/public_html/admin/staff-tasks/view-employee-tasks.php on line 53 No results to display! The whole coding I have is below <?php ini_set('display_startup_errors',1); ini_set('display_errors',1); error_reporting(-1); ?> <!DOCTYPE html> <html> <head> <title>View Tasks</title> <link rel="stylesheet" type="text/css" media="screen" href="css/login-styles.css" /> </head> <body> <h2>View Tasks</h2> <? session_start(); if($_SESSION['user']==''){ header("Location:login.php"); }else{ include("config.php"); $sql=$dbh->prepare("SELECT * FROM employee WHERE emp_id=?"); $sql->execute(array($_SESSION['user'])); while($r=$sql->fetch()){ echo "<div class='home-content'>"; echo "<center><h2>Hello, ".$r['username']."</h2>"; echo "<a href='logout.php'>Log Out</a></center>"; echo "</div>"; } } ?> <?php include("db-connect.php"); // get the records from the database if ($result = $mysqli->query("SELECT e.emp_id , t.task_id , t.description , t.status FROM employee e JOIN assignment a ON e.emp_id = a.emp_id JOIN task t ON a.task_id = t.task_id WHERE e.emp_id = ?")); $sql->execute(array($_SESSION['user'])); { // display records if there are records to display if ($result->num_rows > 0) { // display records in a table echo "<table>"; // set table headers echo "<tr> <th>Task ID</th> <th>Description</th> <th>Status</th> <th>Emp ID</th> <th>Status</th> <th colspan='1'>Actions</th> </tr>"; while ($row = $result->fetch_object()) { // set up a row for each record echo "<tr>"; echo "<td>" . $row->task_id . "</td>"; echo "<td>" . $row->description . "</td>"; echo "<td>" . $row->status . "</td>"; echo "<td>" . $row->emp_id . "</td>"; echo "<td>" . $row->status . "</td>"; echo "<td><a href='records.php?task_id=" . $row->task_id . "'>Edit</a></td>"; echo "</tr>"; } echo "</table>"; } // if there are no records in the database, display an alert message else { echo "No results to display!"; } } // show an error if there is an issue with the database query /*else { echo "Error: " . $mysqli->error; }*/ // close database connection $mysqli->close(); ?> </body> </html>
-
Ok Instead of $LoggedInUser, what would it be as not got $loggedInUser in where I am storing their id in the $_SESSION variable
-
Is that bit like what I have done below <? session_start(); if($_SESSION['user']==''){ header("Location:login.php"); }else{ include("config.php"); $sql=$dbh->prepare("SELECT * FROM employee WHERE emp_id=?"); $sql->execute(array($_SESSION['user'])); while($r=$sql->fetch()){ echo "<div class='home-content'>"; echo "<center><h2>Hello, ".$r['username']."</h2>"; echo "<a href='logout.php'>Log Out</a></center>"; echo "</div>"; } } ?>