dongse5408 2014-08-03 03:15
浏览 94

使用PHP表单编辑XML文件

I have an XML file that I want to be able to edit using a form.

student.xml

<students>
  <student>
    <name>Jane Doe</name>
    <email>email@email.com</email>
    <school>School Name</school>
    <coach>Coach Name</coach>
  </student>
</students>

Basically my form is set up like this:

<form method="post">
  <input name="name" id="name" type="text">
  <input name="school" id="school" type="text">
  <input name="coach" id="coach" type="text">
  <br>
  <input type="submit" name="submit" value="submit">
</form>

PHP code:

<?php
if(isset($_POST['submit'])) {
$data=simplexml_load_file('student.xml');

$data->student->name=$_POST['name'];
$data->student->school=$_POST['school'];
$data->student->coach=$_POST['coach'];

$handle=fopen("student.xml","wb");
fwrite($handle,$data->asXML());
fclose($handle);
}

$data=simplexml_load_file('student.xml');

?>

How can I use a form to edit multiple nodes in one form? Right now it changes all the nodes to the same as the first one.

Edit: Code is updated. It all seems to be working now. Thanks for the help.

  • 写回答

2条回答 默认 最新

  • doumizhi0809 2014-08-03 04:23
    关注

    I have noticed that you are using <form action= method="post">. It must be changed to:

    <form action="" method="post">
    

    Also, if you want to link to a file, it must be like <form action="afile.html" method="post">.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动