2013-12-20 25 views
0

我有很難做一個PHP後到這裏XML數據是我的表格:HTML文章到PHP來生成XML文件?

<form action="../xml/data.php" method"post"> 
    <p>Name</p> 
    <input name='name' required><br> 
    <p>ID</p> 
    <input name"id" required> 
    <input type='submit' value ="submit" name="submit"> 
</form> 

這裏是我的PHP代碼:

<?php 
$s_id=$_POST['id']; 
$s_name=$_POST['name']; 
$xml = new DOMDocument("1.0"); 
$student = $xml -> createElement("student"); 
$xml -> appendChild($student); 

$id_value = $xml ->createTextNode("$s_id"); 
$id -> appendChild($id_value); 
$name = $xml -> createElement("name"); 
$student -> appendChild($name); 
$name_value=$xml->createTextNode("$s_name"); 
$name->appendChild($name_value); 
$xml ->formatOutput = true; 

$xml -> save("mydata.xml"); 
?> 

不過,這並不使MYDATA .xml文件,而不是工作:不是知道我在做什麼錯在這裏

+1

它在什麼時候突破?它是否到了最後,但你可以找到一個文件,或者它是否在其他地方,它的錯誤?你看到一個錯誤,給你一個線看?這些都是應該回答的重要問題。 –

+0

我在提交表單後出現錯誤:注意:未定義索引:在線2中的ID 注意:未定義索引:第3行\ xml \ data.php中的名稱 注意:未定義變量:data.php中的id第9行在提交表單後出現錯誤: – user2922625

+0

爲什麼我們應該認爲'$ id'具有'DOMDocument'屬性?你想在哪裏添加存儲在'$ id_value'中的文本? – PHPglue

回答

0

你錯過了你的表單標籤的=什麼:

<form action="../xml/data.php" method"post"> 

應該

<form action="../xml/data.php" method="post"> 

和這裏

<input name"id" required> 

應該

<input name="id" required> 

@PHPglue是正確的太 - $id -> appendChild($id_value);應該大概是$student -> appendChild($id_value);

+0

仍然得到錯誤提交表單後,不確定的指數錯誤 – user2922625

+0

你錯過了另一個'=',已經更新了我的答案 –

+0

現在開始,在線9 – user2922625

0

你缺少了幾等於在你的表單代碼的跡象:

<form action="../xml/data.php" method"post"> 

<input name"id" required> 

應該是:

<form action="../xml/data.php" method="post"> 

<input name="id" required> 
+0

仍然收到未定義的索引:id第2行和第5行 – user2922625