Hi
I have managed to get the record inserted successfully to the database but am stuck with updating the record using a php form, the data is stored across multiple tables, my database looks like the following
assignment table has the following columns
assign_id
emp_id
task_id
employee table has the following columns
emp_id
username
password
psalt
emp_name
task table has the following columns
task_id
description
status
I’t don’t show any errors, it just shows the h2 title and the label
I have attached a screenshot of how it looks and the current code I have
[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())
{
var_dump($sql);
?>
<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;
}
?>
I don’t get it and can’t work it out where I have gone wrong, can someone help me please
Thank you in advance
Ian
[canned-message]attachments-removed-during-migration