通过php表单修改我的

通过php表单修改我的

本文介绍了通过php表单修改我的

问题描述

这是我的

问题是我想在那之后修改信息.如何通过标签名称获取元素,以便我可以修改特定学生的信息?

<学生><firstname>John</firstname><lasttname>Snow</lasttname><student_id>160600</student_id><性别>男性</性别><dob>23-06-95</dob><email>[email protected]</email><手机号码>57675060</手机号码><address>albatros, portlouis</address><群组>BSE15PT</群组><程序>软件工程</程序><mode>PT</mode></学生><学生><firstname>Jey</firstname><lastname>Lacroix</lastname><student_id>150501</student_id><gender>M</gender><dob>1990-02-22</dob><email>[email protected]</email><手机号码>57553536</手机号码><address>Curepipe</address><群组>BSE15AFT</群组><程序>软件工程</程序><mode>FT</mode></学生></学生>
 
";//rint_r($array);//echo "</pre>";$count=0;$size=count($array);//echo $count;echo "";while($count!=count($array)){foreach ($array[$count]->children() as $child) {//将值存储在 child$getElementTag=$child->getName();//获取标签所以nomecho ''." ";echo '<input type="text" value=" '.$child.'" size="30"></input>';echo "
";echo "
";}$count++;}echo ''.'
';echo "*******************************";echo "</center>";}?><!DOCTYPE html><头><title>搜索</title><身体><中心><form method="POST" action="searchtest.php"><label>输入学生姓名</label><input type="text" name="studentname" pattern="[A-Z][a-z]+" title="必须以大写字母开头!"需要><br><br><input type="submit" name="search" value="search"></表单></中心></html>
解决方案

考虑动态的

输出

(新文件不会覆盖现有文件,看看 Jess StackOverflow 如何替换旧的 John Snow)

This is my

The issue is that I want to modify the information after that. How can I get the element by tag name so that I can modify the information about the specific student?

<students>
  <student>
    <firstname>John</firstname>
    <lasttname>Snow</lasttname>
    <student_id>160600</student_id>
    <gender>male</gender>
    <dob>23-06-95</dob>
    <email>[email protected]</email>
    <mobilenumber>57675060</mobilenumber>
    <address>albatros, portlouis</address>
    <cohort>BSE15PT</cohort>
    <programme>Software Engineering</programme>
    <mode>PT</mode>
  </student>
  <student>
    <firstname>Jey</firstname>
    <lastname>Lacroix</lastname>
    <student_id>150501</student_id>
    <gender>M</gender>
    <dob>1990-02-22</dob>
    <email>[email protected]</email>
    <mobilenumber>57553536</mobilenumber>
    <address>Curepipe</address>
    <cohort>BSE15AFT</cohort>
    <programme>software engineering</programme>
    <mode>FT</mode>
  </student>
</students>
    <?php
    if(isset($_POST['search']))
{
    $
解决方案

Consider a dynamic XSLT (the transformation language used to modify

  1. You need <form> tags to initiate the $_POST array and send values to server-side. Add needed action below.
  2. You need to give each <input> a distinct name which you already have with $getElementTag. Consider sanitizing the server side $_POST values.
  3. You need a hidden input field to retain the old firstname in case the user changes this value. This field is important as it is used in XSLT to select the appropriate <student> node to update.

PHP Script

Below script contains only the two if (isset(...) conditionals. Integrate into your full script and be sure echoes do not appear above <html> and <head>. Also, the embedded XSLT string is included. Be sure to have the XSLTProcessor extension (php_xsl.dll or php_xsl.so) enabled in .ini file.

<?php

$

HTML Input

Output

(new file does not overwrite existing, see how the Jess StackOverflow replaces the old John Snow)

<?

这篇关于通过php表单修改我的

08-19 02:54