我有一个显示所有读取记录的access.php
代码:
<div class='tile-body'>
<table id='access' class='display responsive nowrap' cellspacing='0' width='100%'>
<thead>
<tr>
<th>ID</th>
<th>First name</th>
<th>Last name</th>
<th>Therapist</th>
<th>Postcode</th>
<th>Access Type</th>
<th>Access Code</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
// include database connection
include 'include/database.php';
$action = isset($_GET['action']) ? $_GET['action'] : "";
// if it was redirected from delete.php
if($action=='deleted'){
echo "<div class='alert alert-success'>Record was deleted.</div>";
}
// select all data
$query = "SELECT id, firstname, lastname, therapist, postcode, access_type, code FROM access ORDER BY id DESC";
$stmt = $con->prepare($query);
$stmt->execute();
// this is how to get number of rows returned
$num = $stmt->rowCount();
//check if more than 0 record found
if($num>0){
// retrieve our table contents
// fetch() is faster than fetchAll()
// http://stackoverflow.com/questions/2770630/pdofetchall-vs-pdofetch-in-a-loop
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
// extract row
// this will make $row['firstname'] to
// just $firstname only
extract($row);
// creating new table row per record
echo "<tr>";
echo "<td>{$id}</td>";
echo "<td>{$firstname}</td>";
echo "<td>{$lastname}</td>";
echo "<td>{$therapist}</td>";
echo "<td>{$postcode}</td>";
echo "<td>{$access_type}</td>";
echo "<td>{$code}</td>";
echo "<td>";
// read one record
echo "<a href='access_one.php?id={$id}' class='btn btn-info m-r-1em'>Read</a>";
// we will use this links on next part of this post
echo "<a href='upd_access.php?id={$id}' class='btn btn-primary m-r-1em'>Edit</a>";
// we will use this links on next part of this post
echo "<a href='del_access.php?id={$id}' class='btn btn-danger'>Delete</a>";
echo "</td>";
echo "</tr>";
}
}
?>
</tbody>
</table>
</div>
现在,我有一个edit_access.php
在下一页打开,但我想要做的是加载模型对话框。尝试了不同的选择,但每条道路的id都没有弹出。我只是弹出相同的编辑记录。
<div class="container w-420 p-15 bg-white mt-40 text-center">
<?php if(isset($status)){ echo $status; }?>
<!-- validation error -->
<?php
//check for any errors
if(isset($error)){
foreach($error as $error){
echo "<br/>";
echo '<span class="alert alert-danger alert-dismissable" text-align="center">'.$error.'</span>';
echo "<br/>";
}
}
//if(isset($msg)){ echo $msg;}
?>
<h2 class="text-light text-greensea">Update Record</h2>
<?php
error_reporting(E_ALL); ini_set('display_errors', 1);
// include database connection
include 'include/database.php';
// get passed parameter value, in this case, the record ID
// isset() is a PHP function used to verify if a value is there or not
$id=isset($_GET['id']) ? $_GET['id'] : die('ERROR: Record ID not found.');
// check if form was submitted
if($_POST){
try{
// write update query
// in this case, it seemed like we have so many fields to pass and
// it is better to label them and not use question marks
$query = "UPDATE access SET firstname=:firstname, lastname=:lastname, therapist=:therapist, postcode=:postcode, access_type=:access_type, code=:code WHERE id = :id";
// prepare query for excecution
$stmt = $con->prepare($query);
// posted values
$firstname=htmlspecialchars(strip_tags($_POST['firstname']));
$lastname=htmlspecialchars(strip_tags($_POST['lastname']));
$therapist=htmlspecialchars(strip_tags($_POST['therapist']));
$postcode=htmlspecialchars(strip_tags($_POST['postcode']));
$access_type=htmlspecialchars(strip_tags($_POST['access_type']));
$code=htmlspecialchars(strip_tags($_POST['code']));
// bind the parameters
// bind the parameters
$stmt->bindParam(':firstname', $firstname);
$stmt->bindParam(':lastname', $lastname);
$stmt->bindParam(':therapist', $therapist);
$stmt->bindParam(':postcode', $postcode);
$stmt->bindParam(':access_type', $access_type);
$stmt->bindParam(':code', $code);
$stmt->bindParam(':id', $id);
// Execute the query
if($stmt->execute()){
echo "<div class='alert alert-success'>Record was updated.</div>";
}else{
echo "<div class='alert alert-danger'>Unable to update record. Please try again.</div>";
}
}
// show errors
catch(PDOException $exception){
die('ERROR: ' . $exception->getMessage());
}
}
?>
<form name="update" class="form-validation mt-20" novalidate="" action="upd_access.php?id=<?php echo htmlspecialchars($id); ?>" method="post" autocomplete='off'>
<div class="form-group">
<input type="text" name="firstname" class="form-control underline-input" value='<?php echo htmlspecialchars($firstname, ENT_QUOTES); ?>' placeholder='firstname'></td>
</div>
<div class="form-group">
<input type="text" name="lastname" class="form-control underline-input" value='<?php echo htmlspecialchars($lastname, ENT_QUOTES); ?>' placeholder='lastname'></td>
</div>
<div class="form-group">
<input type="text" name="therapist" class="form-control underline-input" value='<?php echo htmlspecialchars($therapist, ENT_QUOTES); ?>' placeholder='therapist'></td>
</div>
<?php $access_type = $access_type; ?>
<div class="form-group ">
<label for="work status">Access Type</label>
<div name="access_type" value='<?php echo htmlspecialchars($access_type, ENT_QUOTES); ?>'>
<label class="checkbox-inline checkbox-custom">
<input type="checkbox" name="access_type" <?php if (isset($access_type) && $access_type == "Keysafe") echo "checked"; ?> value="Keysafe"><i></i>Keysafe
</label>
<label class="checkbox-inline checkbox-custom">
<input type="checkbox" name="access_type" <?php if (isset($access_type) && $access_type == "keylog") echo "checked"; ?> value="keylog"><i></i>Keylog
</label>
</div>
</div>
<div class="form-group">
<input type="text" name="code" class="form-control underline-input" value='<?php echo htmlspecialchars($code, ENT_QUOTES); ?>' placeholder='access code'></td>
</div>
<div class="form-group">
<input type="text" name="postcode" class="form-control underline-input" value='<?php echo htmlspecialchars($postcode, ENT_QUOTES); ?>' placeholder='postcode'></td>
</div>
<div class="form-group text-left mt-20">
<button type="submit" class="btn btn-primary pull-right">Update Access</button>
<a href="access.php">
<button type="button" class="btn btn-greensea b-0 br-2 mr-5">Back To Record</button>
</a>
</div>
</form>
</div>
<!-- end of container -->
请帮忙吗?