0
これは私のxmlファイルと私のPHPコードです。私は私のPHPフォームのテキストボックスを介してファーストネームで検索したい、私は特定の学生についてのすべての情報を表示したいが、問題は私のXPathが動作していないということです。 xpathのヘルプ。検索を使用してphpとxmlの構文解析
<students>
<student>
<firstname>John</firstname>
<lasttname>Snow</lasttname>
<student_id>160600</student_id>
<gender>male</gender>
<dob>23-06-95</dob>
<age>21</age>
<email>[email protected]</email>
<mobilenumber>57675060</mobilenumber>
<address>Winter Fel</address>
<cohort>BSE15PT</cohort>
<programme>Software Engineering</programme>
<mode>PT</mode>
</student>
<student>
<firstname>meryl</firstname>
<lastname>Burton</lastname>
<student_id>150500</student_id>
<gender>female</gender>
<dob>26-07-95</dob>
<email>[email protected]</email>
<mobilenumber>57800603</mobilenumber>
<address>rose hill</address>
<cohort>BSE15AFT</cohort>
<programme>software engineering</programme>
<mode>ft</mode>
</student>
</students>
<?php
if(isset($_POST['search']))
{
$xml=simplexml_load_file("studentInstance.xml") or die("Error: Cannot Create Object");
$xpath = $xml;
//query the document
$name = $_POST['studentname'];
$query = $xpath->query("/students/student/[firstname = '$name']");
echo $query;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Searching</title>
</head>
<body>
<form method="POST" action="searchRecord.php">
<label>Enter Student Name</label>
<input type="text" name="studentname"><br>
<input type="submit" name="search" value="search">
</form>
</body>
</html>
私はわからないと私は携帯電話でんだけど、学生は、私はあなたが特定のインデックス/学生/学生[1]/firstnameのに必要かもしれないと思ったリストです –