gpt4 book ai didi

php - 代码不显示其他表中的记录

转载 作者:行者123 更新时间:2023-11-29 07:21:07 25 4
gpt4 key购买 nike

我创建了一个详细信息页面,在其中我可以通过填写的值过滤人员,但我的表格没有显示地址和简历信息。这两个表位于单独的表中,因此我有地址表和 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>

奇怪的是,当我进入该页面时,它显示了一个错误: 注意: undefined index :D:\Server\root\Website\testing.php 中的地址_street,第 xx 行(对于所有地址和简历)字段)。但是当我过滤某些内容时,它会显示所有内容,就像它应该显示的那样,地址和简历都会显示。

更新:

1

更新 2:删除.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();
?>

最佳答案

此行为可能是因为当您进入页面时,您没有提交 $_POST["search"] ,因此脚本进入仅选择数据的 else 分支来自表 person,所有证据都包含列 street_address

然后您尝试将其打印出来,这就是发生未定义索引问题的地方。

<小时/>

编辑:随着主题的进展,OP遇到了另一个问题 - 当他从 person 中删除记录时,表 cvaddress< 中还有剩余记录.

事实上,您总共需要执行三个 DELETE sql 查询。没有一个。

首先,您必须识别cv表和address表中的记录并删除它们,然后删除人员记录:

DELETE FROM address WHERE address_id='$addressIDForPerson'

其中 $addressIDForPerson 是您尝试删除的 person 表中记录中 person_address 列的值。

第二步是从 cv 表中删除记录,再次通过 person 表中的列值进行标识。

DELETE FROM cv WHERE cv_id='$cvIDForPerson'

其中 $cvIDForPerson 是您尝试删除的 cv 表中记录中 person_cv 列的值。

最后,您删除该人的记录

DELETE FROM person WHERE person_id=`$personID`

其中 $personID 标识您要删除的人员。

关于php - 代码不显示其他表中的记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36128669/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com