我創建了一個詳細頁面,我可以通過填充值過濾人員,我的表格如何不顯示地址和簡歷信息。這兩個是在單獨的表中,所以我有他們自己的值地址表和cv(pdf文件)表。代碼未顯示來自其他表的記錄
<?php
if(isset($_POST['search']))
{
$valueToSearch = $_POST['valueToSearch'];
// search in all table columns
// using concat mysql function
$query = "SELECT person_id, person_firstname, person_lastname,
person_email, person_phonenumber,
address_street,address_housenumber,
address_city,address_state,address_zipcode,cv_path
FROM person
inner join address on address.address_id = person.person_address
inner join cv on cv.cv_id = person.person_cv
WHERE CONCAT(`person_firstname`, `person_lastname`, `address_street`, `address_housenumber`, `address_zipcode`, `address_city`, `address_state`, `person_email`, `person_phonenumber`)
LIKE '%".$valueToSearch."%'";
$search_result = filterTable($query);
}
else {
$query = "SELECT * FROM `person`";
$search_result = filterTable($query);
}
// function to connect and execute the query
function filterTable($query)
{
$connect = mysqli_connect("localhost", "root", "usbw", "persons");
$filter_Result = mysqli_query($connect, $query);
return $filter_Result;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>PHP HTML TABLE DATA SEARCH</title>
<style>
table,tr,th,td
{
border: 1px solid black;
}
</style>
</head>
<body>
<form action="testing.php" method="post">
<input type="text" name="valueToSearch" placeholder="Value To Search"><br><br>
<input type="submit" name="search" value="Filter"><br><br>
<table>
<tr>
<th>Voornaam</th>
<th>Achternaam</th>
<th>Straat</th>
<th>Huisnummer</th>
<th>Postcode</th>
<th>Stad</th>
<th>Provincie</th>
<th>Email</th>
<th>Mobiel</th>
<th>cv</th>
<th>delete</th>
</tr>;
<!-- populate table from mysql database -->
<?php while($row = mysqli_fetch_array($search_result)):?>
<tr>
<td><?php echo $row['person_firstname'];?></td>
<td><?php echo $row['person_lastname'];?></td>
<td><?php echo $row['address_street'];?></td>
<td><?php echo $row['address_housenumber'];?></td>
<td><?php echo $row['address_zipcode'];?></td>
<td><?php echo $row['address_city'];?></td>
<td><?php echo $row['address_state'];?></td>
<td><?php echo $row['person_email'];?></td>
<td><?php echo $row['person_phonenumber'];?></td>
<td><?php echo "<a href='http://localhost:8080/website/" . $row['cv_path'] . "'>cv file</a>";?></td>
<td><?php echo "<a href='delete.php?person_id=" . $row['person_id'] . "'>delete</a>";?></td>
</tr>
<?php endwhile;?>
</table>
</form>
</body>
</html>
這一切奇怪的是,當我去的網頁它顯示了我的錯誤:注意:未定義指數:address_street在d:\上線XX服務器\ ROOT \網站\ testing.php(用於所有地址和cv fiels)。但是當我過濾一些東西時,它會顯示所有的東西,就像地址和簡歷顯示一樣。
UPDATE:
UPDATE2: Delete.php:
<?php
$servername = "localhost";
$username = "root";
$password = "usbw";
$dbname = "persons";
// CREATE A CONNECTION WITH THE DATABASE
// CONNECTIE MAKEN MET DATABASE
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// GET ID FROM person_id
// PAK ID VAN person_id
$id=$_GET['person_id'];
// CREATE PREPARE STATMENT FOR DELETING RECORDS FROM person_id
// MAAK EEN STATEMENT OM WAARDES TE VERWIJDEREN VAN person_id
$stmt = $conn->prepare('DELETE FROM person WHERE person_id = ?');
$stmt->bind_param('s', $id);
// EXECUTE STATEMENT AND IF RESULT IS FALSE SHOW ERROR
// VOER STATEMENT UIT EN ALS VALS IS GEEF ERROR AAN
$result = $stmt->execute();
if ($result === FALSE) {
die("Error: " . $stmt->error);
}
// AFTER CLICKING DELETE GO TO LINK
// NA HET DRUKKEN VAN DELETE GA NAAR LINK
header("Location: http://localhost:8080/Website/admin.php");
// CLOSE CONNECTION AND STATEMENT
// SLUIT CONNECTIE EN STATEMENT
$stmt->close();
$conn->close();
?>
你的連接條款在哪裏? –
哎呀!等待一分鐘我有其他選擇代碼 – GLRotterdam