我制作了一个名为display Patient的页面,其中有一个表格,当点击view_all
选项时,该表格将显示数据库中所有患者的信息。
我希望制作一个额外的行,允许用户点击编辑,它将编辑该特定行的信息。
我目前还没有想出如何使edit_patient.php
接受所有值。
我尝试使用
echo "<td>". ?><a href="edit_patient.php?id=<?php echo
urlencode($patients["id"]) .?>">Edit</a> "</td>"
但它不起作用并显示error of unexpected ';'.
显示患者
<?php require_once("includes/session.php"); ?>
<?php require_once("includes/db_connection.php"); ?>
<?php require_once("includes/functions.php"); ?>
<?php $layout_context = "admin"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style>
table {border:3px solid black; border-collapse:collapse; margin: 0 auto;}
tr { background-color:white;}
th {font-size: 20px;}
td {font-size: 18px; margin-left: 10px; margin-right: 10px;}
input {border-radius: 4px; border-color: black; margin-top: 10px; margin-bottom:10px;}
h2 {margin-left:6%;}
</style>
</head>
<body>
<h2>View Patient Records</h2>
<body>
<form action="display_patient.php" method="post">
<p>Select:
<select name="patient_var" >
<?php
$value = array(view_all, last_name, address);
foreach ($value as $option)
{
echo '<option value="'.$option.'"' . (isset($_POST['patient_var']) && $_POST['patient_var'] == $option ? ' selected' : '') . '>' . $option . '</option>';
}
?>
</select>
<input type="text" name="typed" value="" />
<input type ="submit" value="submit" />
</form>
</p>
<p>
<?php
if (isset($_POST['patient_var'])) {
$type = $_POST['typed'];
$select = $_POST['patient_var'];
if ($select == 'view_all') {
echo "<table border='1'>";
echo "<tr>\n";
echo "<th>ID</th>\n";
echo "<th>First Name</th>\n";
echo "<th>Last Name</th>\n";
echo "<th>Age</th>\n";
echo "<th>NRIC</th>\n";
echo "<th>Birth Date</th>\n";
echo "<th>Medical Allergies</th>\n";
echo "<th>Medical History</th>\n";
echo "<th>Phone</th>\n";
echo "<th>Address</th>\n";
echo "<th>Doctor Assigned</th>\n";
echo "</tr>";
$pat_set = default_patient();
while ($mo = mysqli_fetch_array($pat_set)) {
echo "<tr>";
echo "<td>" . $mo['id'] . "</td>";
echo "<td>". $mo['first_name'] . "</td>";
echo "<td>". $mo['last_name'] . "</td>";
echo "<td>". $mo['age'] . "</td>";
echo "<td>". $mo['nric'] . "</td>";
echo "<td>". $mo['birthdate'] . "</td>";
echo "<td>". $mo['medical_allergies'] . "</td>";
echo "<td>". $mo['medical_history'] . "</td>";
echo "<td>". $mo['phone'] . "</td>";
echo "<td>". $mo['address'] ."</td>";
echo "<td>". $mo['doctor_assigned'] . "</td>";
echo '<td><a href="edit_patient.php?id='.urlencode($mo["id"]).'">Edit</a></td>';
echo "</tr>";
}
}
else {
echo "<table border='1'>\n";
echo "<tr>\n";
echo "<th>ID</th>\n";
echo "<th>First Name</th>\n";
echo "<th>Last Name</th>\n";
echo "<th>Age</th>\n";
echo "<th>NRIC</th>\n";
echo "<th>Birth Date</th>\n";
echo "<th>Medical Allergies</th>\n";
echo "<th>Medical History</th>\n";
echo "<th>Phone</th>\n";
echo "<th>Address</th>\n";
echo "<th>Doctor Assigned</th>\n";
echo "</tr>";
$patients_set =
find_patients($select, $type);
while ($row = mysqli_fetch_array($patients_set))
{ echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>". $row['first_name'] . "</td>";
echo "<td>". $row['last_name'] . "</td>";
echo "<td>". $row['age'] . "</td>";
echo "<td>". $row['nric'] . "</td>";
echo "<td>". $row['birthdate'] . "</td>";
echo "<td>". $row['medical_allergies'] . "</td>";
echo "<td>". $row['medical_history'] . "</td>";
echo "<td>". $row['phone'] . "</td>";
echo "<td>". $row['address'] ."</td>";
echo "<td>". $row['doctor_assigned'] . "</td>";
echo "</tr>"; }
}
}//end of if post submit
?>
</p>
</div>
</body>
</html>
功能
function default_patient(){
global $connection;
$query = "SELECT * ";
$query .= "From patients ";
$query .= "ORDER BY id ASC";
$pat_set = mysqli_query($connection, $query);
confirm_query($pat_set);
return $pat_set;
}
function find_patients($select, $type) {
global $connection;
$safe_type = mysqli_real_escape_string($connection, $type);
$safe_select = mysqli_real_escape_string($connection, $select);
$query = "SELECT * ";
$query .= "FROM patients ";
$query .= "WHERE {$safe_select} LIKE '%".$safe_type."%' ";
$query .= "ORDER BY id ASC";
$patients_set = mysqli_query($connection, $query);
confirm_query($patients_set);
return $patients_set;
}
edit_patient
<?php require_once("includes/session.php"); ?>
<?php require_once("includes/db_connection.php"); ?>
<?php require_once("includes/functions.php"); ?>
<?php require_once("includes/validation_function.php"); ?>
<?php find_selected_page(); ?>
<?php
if (isset($_POST['submit'])) {
// Process the form
//validations
$required_fields = array("first_name", "last_name", "postalcode", "nric", "address", "phone", "doctor");
validate_presences($required_fields);
$fields_with_max_lengths = array("phone" => 8);
validate_max_lengths($fields_with_max_lengths);
if( verify_nric($_POST['nric'])) {
$errors[] = 'This NRIC exists already.';
}
if( !isValid( 'phone', $_POST['phone'] ) ) {
$errors[] = 'Please enter a valid phone number';
}
if( !isValid( 'nric', $_POST['nric'] ) ) {
$errors[] = 'Please enter a valid nric number';
}
if (empty($errors)) {
// perform Create
$d=$_POST['day'];
$m=$_POST['month'];
$y=$_POST['year'];
//converting Inputed DOB in "dd-mm-yyyy" format
$dob=$d.'-'.$m.'-'.$y;
//Create a new date object with current system date
$bday=new DateTime($dob);
//Differentiating both dates
$age=$bday->date_diff(new DateTime);
$today=date('d-m-Y');
$birthdate = mysql_prep($dob);
$c_age = $age->y;
$name = mysql_prep($_POST["name"]);
$nric = mysql_prep($_POST["nric"]);
$allergy = mysql_prep($_POST["medical_allergy"]);
$history = mysql_prep($_POST["medical_history"]);
$phone = (int)$_POST["phone"];
$address = mysql_prep($_POST["address"]);
$doctor = mysql_prep($_POST["doctor"]);
//escape content
// 2. Perform database query
$query = "INSERT INTO patients (";
$query .= " name, age, nric, birthdate, medical_allergies, medical_history,
phone, address, doctor_assigned";
$query .= ") VALUES (";
$query .= " '{$name}', {$c_age}, '{$nric}', '{$birthdate}',
'{$allergy}', '{$history}', {$phone}, '{$address}', '{$doctor}'";
$query .= ")";
$result = mysqli_query($connection, $query);
if ($result ) {
// Success
$_SESSION["message"] = "Record Updated.";
}else {
// Failure
$_SESSION["message"] = "Record creation failed.";
}
}
} else {
// This is probably a GET request
} // End: If(isset($_POST['submit']))
?>
<head>
<title>Dashboard - H H Lee & Associates Dental Surgery</title>
<style>
table {border:3px solid black; border-collapse:collapse; margin: 0 auto;}
tr { background-color:white; }
td { padding-left: 10px; }
textarea{border-radius: 4px; border: 2px solid black; resize:none; margin-top: 10px; margin-bottom:10px;}
input {border-radius: 4px; border: 2px solid black; margin-top: 10px; margin-bottom:10px;}
h2 {margin-left:6%;}
input[type=text]
{
padding: 5px 10px;
}
input[type=submit]
{
padding: 5px 20px;
border-radius: 10px;
background-color: #fff;
color: #008080;
font-weight: bold;
}
input[type=submit]:hover
{
padding: 5px 20px;
border-radius: 10px;
background-color: #008080;
color: #fff;
font-weight: bold;
}
#admin_back
{
margin-top: -15px;
margin-bottom: 15px;
}
</style>
</head>
<?php $layout_context = "admin"; ?>
<?php echo message(); ?>
<?php echo form_errors($errors); ?>
<h2>EDIT A PATIENT RECORD</h2>
<form action="create_patient.php" style="text-align: left;
margin-left:6%;"method="post">
<table border='1' width='70%'>
<tr>
<td>ID of patient</td>
<td><input type="text" name="patient_id" value="" /></td>
</tr>
<tr>
<td>First Name:</td>
<td><input type="text" name="first_name" value="" /></td>
</tr>
<tr>
<td>Last Name:</td>
<td><input type="text" name="last_name" value="" /></td>
</tr>
<tr>
<td> NRIC/ Foreign ID/ Passport:</td>
<td><input type="text" name="nric" value="" /></td>
</tr>
<tr>
<td>Date Of Birth:<br /></td>
<td>Day<br/>
<select name="day"> <!-- To Select Day -->
<option value="01" selected="selected">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
<option value="32">32</option>
</select>
Month
<select name="month"><!--TO Select Month-->
<option value="01" selected="selected">Jan</option>
<option value="02">Feb</option>
<option value="03">Mar</option>
<option value="04">Apr</option>
<option value="05">May</option>
<option value="06">Jun</option>
<option value="07">Jul</option>
<option value="08">Aug</option>
<option value="09">Sep</option>
<option value="10">Oct</option>
<option value="11">Nov</option>
<option value="12">Dec</option>
</select>
Year
<select name="year"><!--To Select Year-->
<option value="2013" selected="selected">2013</option>
<option value="2012">2012</option>
<option value="2011">2011</option>
<option value="2010">2010</option>
<option value="2009">2009</option>
<option value="2008">2008</option>
<option value="2007">2007</option>
<option value="2006">2006</option>
<option value="2005">2005</option>
<option value="2004">2004</option>
<option value="2003">2003</option>
<option value="2002">2002</option>
<option value="2001">2001</option>
<option value="2000">2000</option>
<option value="1999">1999</option>
<option value="1998">1998</option>
<option value="1997">1997</option>
<option value="1996">1996</option>
<option value="1995">1995</option>
<option value="1994">1994</option>
<option value="1993">1993</option>
<option value="1992">1992</option>
<option value="1991">1991</option>
<option value="1990">1990</option>
<option value="1989">1989</option>
<option value="1988">1988</option>
<option value="1987">1987</option>
<option value="1986">1986</option>
<option value="1985">1985</option>
<option value="1984">1984</option>
<option value="1983">1983</option>
<option value="1982">1982</option>
<option value="1981">1981</option>
<option value="1980">1980</option>
<option value="1979">1979</option>
<option value="1978">1978</option>
<option value="1977">1977</option>
<option value="1976">1976</option>
<option value="1975">1975</option>
<option value="1974">1974</option>
<option value="1973">1973</option>
<option value="1972">1972</option>
<option value="1971">1971</option>
<option value="1970">1970</option>
<option value="1969">1969</option>
<option value="1968">1968</option>
<option value="1967">1967</option>
<option value="1966">1966</option>
<option value="1965">1965</option>
<option value="1964">1964</option>
<option value="1963">1963</option>
<option value="1962">1962</option>
<option value="1961">1961</option>
<option value="1960">1960</option>
<option value="1959">1959</option>
<option value="1958">1958</option>
<option value="1957">1957</option>
<option value="1956">1956</option>
<option value="1955">1955</option>
<option value="1954">1954</option>
<option value="1953">1953</option>
<option value="1952">1952</option>
<option value="1951">1951</option>
<option value="1950">1950</option>
<option value="1949">1949</option>
<option value="1948">1948</option>
<option value="1947">1947</option>
<option value="1946">1946</option>
<option value="1945">1945</option>
<option value="1944">1944</option>
<option value="1943">1943</option>
<option value="1942">1942</option>
<option value="1941">1941</option>
<option value="1940">1940</option>
<option value="1939">1939</option>
<option value="1938">1938</option>
<option value="1937">1937</option>
</select>
</td></tr>
<tr>
<td>Contact Number:</td>
<td><input type="text" name="phone" value="" /></td>
</tr>
<tr>
<td>Address:</td>
<td><textarea name="address" rows="3" cols="60" align="right"></textarea></td>
</tr>
<tr>
<td>Postal Code:</td>
<td><input type="text" name="postalcode" value="" /></td>
</tr>
<tr>
<td>Dentist Assigned:</td>
<td><input type="text" name="doctor" value="" /></td>
</tr>
<tr><td>Medical Allergies:</td>
<td><textarea name="medical_allergy" rows="10" cols="60"></textarea></p></td>
</tr>
<tr>
<td>Medical History:</td>
<td><textarea name="medical_history" rows="10" cols="60"></textarea></td>
</tr>
<tr>
<td colspan="2" style="text-align: center;">
<input type="submit" name="submit" value="Submit"/>
<a href="manage_content.php">Cancel</a>
</td>
</tr>
</table>
</form>
</div>
答案 0 :(得分:0)
我认为你的回声线有点破碎,并且没有;试试这个。
<?php
echo '<td><a href="edit_patient.php?id='.urlencode($patients["id"]).'">Edit</a></td>';
?>