在此,我想在每一行中添加一個查看按鈕。所以,當我點擊查看按鈕時,它會轉到那個特定的人並顯示他的細節。如何在每行上添加查看按鈕以查看該特定名稱的詳細信息
這裏是我的代碼:(的index.php)
<?php
include 'DBConfig.php';
//Insert or Update contact information
if(isset($_POST['action_type']))
{
if ($_POST['action_type'] == 'add' or $_POST['action_type'] == 'edit')
{
//Sanitize the data and assign to variables
$contact_id = mysqli_real_escape_string($link, strip_tags($_POST['ContactID']));
$fname = mysqli_real_escape_string($link, strip_tags($_POST['fname']));
$lname = mysqli_real_escape_string($link, strip_tags($_POST['lname']));
$contact_no = mysqli_real_escape_string($link, strip_tags($_POST['ContactNo']));
$Address = mysqli_real_escape_string($link, strip_tags($_POST['Address']));
if ($_POST['action_type'] == 'add')
{
$sql = "insert into tblcontact set
first_name = '$fname',
last_name = '$lname',
contact_no = '$contact_no',
address = '$Address'";
}else{
$sql = "update tblcontact set
first_name = '$fname',
last_name = '$lname',
contact_no = '$contact_no',
address = '$Address',
where contact_id = $contact_id";
}
if (!mysqli_query($link, $sql))
{
echo 'Error Saving Data. ' . mysqli_error($link);
exit();
}
}
header('Location: contactlist.php');
exit();
}
//End Insert or Update contact information
//Start of edit contact read
$gresult = ''; //declare global variable
if(isset($_POST["action"]) and $_POST["action"]=="edit"){
$id = (isset($_POST["ci"])? $_POST["ci"] : '');
$sql = "select contact_id, first_name, last_name,
contact_no,address from tblcontact
where contact_id = $id";
$result = mysqli_query($link, $sql);
if(!$result)
{
echo mysqli_error($link);
exit();
}
$gresult = mysqli_fetch_array($result);
include 'update.php';
exit();
}
//end of edit contact read
//Start Delete Contact
if(isset($_POST["action"]) and $_POST["action"]=="delete"){
$id = (isset($_POST["ci"])? $_POST["ci"] : '');
$sql = "delete from tblcontact
where contact_id = $id";
$result = mysqli_query($link, $sql);
if(!$result)
{
echo mysqli_error($link);
exit();
}
}
//End Delete Contact
//Read contact information from database
$sql = "select contact_id, CONCAT(first_name,' ' , last_name) as contact_name,
contact_no, address from tblcontact";
$result = mysqli_query($link, $sql);
if(!$result)
{
echo mysqli_error($link);
exit();
}
$contact_list = array();
//Loo through each row on array and store the data to $contact_list[]
while($rows = mysqli_fetch_array($result))
{
$contact_list[] = array('contact_id' => $rows['contact_id'],
'contact_name' => $rows['contact_name'],
'contact_no' => $rows['contact_no'],
'address' => $rows['address']);
}
include 'contactlist.php';
exit();
?>
SO是不是免費的代碼編寫服務,你至少應該表現出一定的努力而實現這一 – Viral
那你嘗試做了什麼?請注意,使用SQL的PDO擴展將更容易,因爲您不必轉義特殊字符 – Sw4Tish