0
これは私のXMLファイルと私のPHPコードです。現在の学生に関する情報を変更します。しかし、何人かの学生がいればどうなるでしょうか?私は最初のもの(John Doe)のみを編集することができます。私の2番目の学生情報を編集するにはどうすればいいですか?以前のコードが動作していないので、私は以前の投稿と比べてコードを単純化しました。おかげPHP:PHPフォームでxmlファイルを編集する
<student>
<firstname>John</firstname>
<lasttname>Doe</lasttname>
<student_id>150334</student_id>
<gender>female</gender>
<dob>16-09-94</dob>
<email>[email protected]</email>
<mobilenumber>12345678</mobilenumber>
<address>xxx</address>
<cohort>cohort name</cohort>
<programme>Softwaree Engineering</programme>
<mode>FT</mode>
</student>
<student>
<firstname>firnstmae</firstname>
<lasttname>hahah</lasttname>
<student_id>150500</student_id>
<gender>female</gender>
<dob>24-03-96</dob>
<email>[email protected]</email>
<mobilenumber>57056242</mobilenumber>
<address>addressname</address>
<cohort>cohort name</cohort>
<programme>web developement</programme>
<mode>FT</mode>
</student>
</students>
<?php
if(isset($_POST['submit'])) {
$data=simplexml_load_file('studentdb.xml');
$data->item->firstname=$_POST['firstname'];
$data->item->lasttname=$_POST['lastname'];
$data->item->gender=$_POST['gender'];
$data->item->dob=$_POST['dob'];
$data->item->email=$_POST['email'];
$data->item->mobilenumber=$_POST['mobilenumber'];
$data->item->address=$_POST['address'];
$data->item->cohort=$_POST['cohort'];
$data->item->programme=$_POST['programme'];
$data->item->mode=$_POST['mode'];
$handle=fopen("studentdb.xml","wb");
fwrite($handle,$data->asXML());
fclose($handle);
}
$data=simplexml_load_file('studentdb.xml');
$fName=$data->item->firstname;
$lName=$data->item->lasttname;
$gender=$data->item->gender;
$dob=$data->item->dob;
$email=$data->item->email;
$mobileNo=$data->item->mobilenumber;
$address=$data->item->address;
$cohort=$data->item->cohort;
$programme=$data->item->programme;
$mode=$data->item->mode;
?>
<?php
echo $fName . " ";
echo $lName . " ";
echo $gender . " ";
echo $dob . " ";
echo $email . " ";
echo $mobileNo . " ";
echo $address . " ";
echo $cohort . " ";
echo $programme . " ";
echo $mode . " ";
?>
<form method="post">
Firstname<input type="text" name="firstname" value="<?php echo $fName;?>" placeholder="firstname" pattern="[A-Z][a-z]+" title="Must start with capital letters!"required/> </br></br>
Lastname<input type="text" name="lastname" value="<?php echo $lName;?>"placeholder="lastname" pattern="[A-Z][a-z]+" title="Must start with capital letters!" required/></br></br>
gender
<input type="radio" name="gender" value="M" value="<?php echo $gender;?>"> Male
<input type="radio" name="gender" value="F" value="<?php echo $gender;?>"> Female<br><br>
dob<input type="date" name="dob" placeholder="dob" value="<?php echo $dob;?>" /> </br></br>
email<input type="text" name="email" placeholder="email" value="<?php echo $email;?>"/></br></br>
mobile No:<input type="text" name="mobilenumber" value="<?php echo $mobileNo;?>" placeholder="mobileno" pattern="5[0-9][0-9][0-9][0-9][0-9][0-9][0-9]" title="Must start with 5 followed by 7 digits" required/></br></br>
address<input type="text" name="address" placeholder="address" value="<?php echo $address;?>" title="Must start with capital letters!"required/></br></br>
cohort<input type="text" name="cohort" placeholder="cohort" value="<?php echo $cohort;?>" required /></br></br>
programme<input type="text" name="programme" placeholder="programme" value="<?php echo $programme;?>" required //></br></br>
mode<input type="radio" name="mode" value="FT" value="<?php echo $mode;?>"> Full-Time
<input type="radio" name="mode" value="PT"> Part-Time<br>
<br>
<input name="submit" type="submit" />
</form>
あなたは既に類似のものを投稿していませんか? http://stackoverflow.com/q/39883512/ –