我创建了一个详细信息页面,我可以通过填充值过滤人员,但我的表格没有显示地址和简历信息。这两个是在单独的表中,所以我有地址表和cv(pdf文件)表与自己的值。
netsh firewall set opmode mode = disable
这一切的奇怪之处在于,当我转到页面时,它向我显示错误:注意:未定义的索引:地址xx中的D:\ Server \ root \ Website \ testing.php中的address_street(适用于所有地址和简历) fiels)。但是,当我过滤某些内容时,它会显示所有内容,因此它应该是地址和cv显示。
更新:
UPDATE2: Delete.php:
<?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>
答案 0 :(得分:2)
这种行为可能是因为当您进入页面时,您没有提交$_POST["search"]
,因此脚本会进入else
分支,该分支仅选择来自表person
的数据,而这些数据来自所有证据不包含列street_address
。
然后,您正尝试将其打印出来,这是发生未定义索引问题的地方。
编辑:随着主题的进展,OP遇到了另一个问题 - 当他从人员中删除记录时,表cv
和address
中仍有剩余记录。
实际上你需要总共执行三个DELETE
sql查询。不是一个。
首先,您必须在cv
表和address
表中识别记录并删除它们,然后删除人员记录:
DELETE FROM address WHERE address_id='$addressIDForPerson'
其中$addressIDForPerson
是您要删除的person_address
表记录中person
列的值。
第二步是从cv
表中删除记录,再次由person
表中的列值标识。
DELETE FROM cv WHERE cv_id='$cvIDForPerson'
其中$ cvIDForPerson是您尝试删除的person_cv
表记录中cv
列的值。
最后,你删除了记录人
DELETE FROM person WHERE person_id=`$personID`
$personID
标识您要删除的人。
答案 1 :(得分:0)
在您的查询中:
SELECT *
FROM `person`
LEFT JOIN `address`
LEFT JOIN `cv`
WHERE CONCAT(`person_firstname`, `person_lastname`, `address_street`, `address_housenumber`, `address_zipcode`, `address_city`, `address_state`, `person_email`, `person_phonenumber` ) LIKE '%".$valueToSearch."%'";
我没有看到JOINS的任何ON子句。
你应该把这些条款。