I still don´t know how to get the columns I need and send it to calrecord table, Please help.
<?php
require "../config.php";
require "../common.php";
// This is to view and for me to select the Equipment Number
if (isset($_POST['search'])) {
if (!hash_equals($_SESSION['csrf'], $_POST['csrf'])) die();
try {
$connection = new PDO($dsn, $username, $password, $options);
$sql = "SELECT *
FROM equipment
WHERE mach_no LIKE :mach_no";
$mach_no = $_POST['mach_no'];
$statement = $connection->prepare($sql);
$statement->bindParam(':mach_no', $mach_no, PDO::PARAM_STR);
$statement->execute();
$result = $statement->fetchAll();
} catch(PDOException $error) {
echo $sql . "<br>" . $error->getMessage();
}
}
?>
<?php require "templates/equip_header.php"; ?>
<?php
if (isset($_POST['search'])) {
if ($result && $statement->rowCount() > 0) { ?>
<h2>Results</h2>
<table>
<thead>
<tr>
<th>Equip ID</th>
<th>Machine/Equipment No.</th>
<th>Brand</th>
<th>Description</th>
<th>Serial Number</th>
<th>Cal Interval</th>
</tr>
</thead>
<tbody>
<?php foreach ($result as $row) : ?>
<tr>
<td><?php echo escape($row["equip_id"]); ?></td>
<td><?php echo escape($row["mach_no"]); ?></td>
<td><?php echo escape($row["brand"]); ?></td>
<td><?php echo escape($row["description"]); ?></td>
<td><?php echo escape($row["serial_no"]); ?></td>
<td><?php echo escape($row["cal_interval"]); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php } else { ?>
<blockquote>No results found for <?php echo escape($_POST['mach_no']); ?>.</blockquote>
<?php }
} ?>
<h2>Find Equipment based on Machine Number</h2>
<form method="post">
<input name="csrf" type="hidden" value="<?php echo escape($_SESSION['csrf']); ?>">
<label for="mach_no">Equipment/Machine Number</label>
<input type="text" id="mach_no" name="mach_no">
<input type="submit" name="search" value="View Search">
</form>
<?php
// this is where I view Employees
if (isset($_POST['submit'])) {
if (!hash_equals($_SESSION['csrf'], $_POST['csrf'])) die();
try {
$connection = new PDO($dsn, $username, $password, $options);
$sql = "SELECT *
FROM users
WHERE employeenumber LIKE :employeenumber";
$employeenumber = $_POST['employeenumber'];
$statement = $connection->prepare($sql);
$statement->bindParam(':employeenumber', $employeenumber, PDO::PARAM_STR);
$statement->execute();
$result = $statement->fetchAll();
} catch(PDOException $error) {
echo $sql . "<br>" . $error->getMessage();
}
}
?>
<?php require "templates/users_header.php"; ?>
<?php
if (isset($_POST['submit'])) {
if ($result && $statement->rowCount() > 0) { ?>
<h2>Results</h2>
<table>
<thead>
<tr>
<th>#</th>
<th>First Name</th>
<th>Last Name</th>
<th>Email Address</th>
<th>Employee Number</th>
<th>Department</th>
<th>Date</th>
</tr>
</thead>
<tbody>
<?php foreach ($result as $row) : ?>
<tr>
<td><?php echo escape($row["id"]); ?></td>
<td><?php echo escape($row["firstname"]); ?></td>
<td><?php echo escape($row["lastname"]); ?></td>
<td><?php echo escape($row["email"]); ?></td>
<td><?php echo escape($row["employeenumber"]); ?></td>
<td><?php echo escape($row["department"]); ?></td>
<td><?php echo escape($row["date"]); ?> </td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php } else { ?>
<blockquote>No results found for <?php echo escape($_POST['employeenumber']); ?>.</blockquote>
<?php }
} ?>
<h2>Find user based on Employee Number</h2>
<form method="post">
<input name="csrf" type="hidden" value="<?php echo escape($_SESSION['csrf']); ?>">
<label for="employeenumber">Employee Number</label>
<input type="text" id="employeenumber" name="employeenumber">
<input type="submit" name="submit" value="View Results">
</form>
?>
<?php
// I need then to
if (isset($_POST['submit'])) {
if (!hash_equals($_SESSION['csrf'], $_POST['csrf'])) die();
try {
$connection = new PDO($dsn, $username, $password, $options);
$new_calrec = array(
"equip_id" => $_POST['equip_id'],
"brand" => $_POST['brand'],
"description" => $_POST['description'],
"employeenumber" => $_POST['employeenumber'],
"cal_interval" => $_POST['cal_interval']
);
$sql = sprintf(
"INSERT INTO %s (%s) values (%s)",
"calrecord",
implode(", ", array_keys($new_calrec)),
":" . implode(", :", array_keys($new_calrec))
);
$statement = $connection->prepare($sql);
$statement->execute($new_calrec);
} catch(PDOException $error) {
echo $sql2 . "<br>" . $error->getMessage();
}
}
?>
<?php require "templates/calrec_header.php"; ?>
<?php if (isset($_POST['submit']) && $statement) : ?>
<blockquote><?php echo escape($_POST['equip_id']); ?> successfully added.</blockquote>
<?php endif; ?>
<h2>Add a Calibration Record</h2>
<form method="post">
<input name="csrf" type="hidden" value="<?php echo escape($_SESSION['csrf']); ?>">
<label for="mach_no">Machine/Equipment Number</label>
<input type="text" name="equip_id" id="equip_id">
<input type="submit" name="submit" value="Search">
<label for="brand">Brand</label>
<input type="text" name="brand" id="brand">
<label for="description">Description</label>
<input type="text" name="description" id="description">
<label for="employeenumber">Employee Number</label>
<input type="text" name="employeenumber" id="employeenumber">
<label for="cal_interval">Cal Interval</label>
<input type="text" name="cal_interval" id="cal_interval">
<input type="submit" name="submit" value="Submit">
</form>
<?php
// this is to view the Transaction of Calibrations
try {
$connection = new PDO($dsn, $username, $password, $options);
//open database View of calrecord
$sql = "SELECT * FROM Next_Update";
$statement = $connection->prepare($sql);
$statement->execute();
$result = $statement->fetchAll();
} catch(PDOException $error) {
echo $sql . "<br>" . $error->getMessage();
}
?>
<h2>Calibration Record</h2>
<table>
<thead>
<tr>
<th>Calibration ID</th>
<th>Machine/Equipment No.</th>
<th>Brand</th>
<th>Description</th>
<th>Employee Number</th>
<th>Calibration Interval</th>
<th>Calibration Date</th>
<th>Next Calibration</th>
<th>Edit</th>
</tr>
</thead>
<tbody>
<?php
foreach ($result as $row) : ?>
<tr>
<td><?php echo escape($row["cal_id"]); ?></td>
<td><?php echo escape($row["mach_no"]); ?></td>
<td><?php echo escape($row["brand"]); ?></td>
<td><?php echo escape($row["description"]); ?></td>
<td><?php echo escape($row["employeenumber"]); ?></td>
<td><?php echo escape($row["cal_interval"]); ?></td>
<td><?php echo escape($row["cal_date"]); ?> </td>
<td><?php echo escape($row["next_cal"]); ?> </td>
<td><a href="update-single-calrec.php?id=<?php echo escape($row["cal_id"]); ?>">Edit</a></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<a href="index.php">Back to home</a>
<?php require "templates/footer.php"; ?>