Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP、MYSQL编写和更新XML文件_Php_Mysql_Xml - Fatal编程技术网

使用PHP、MYSQL编写和更新XML文件

使用PHP、MYSQL编写和更新XML文件,php,mysql,xml,Php,Mysql,Xml,我试图根据下拉列表中的用户选择在这里创建一个XML文件, 取决于我的选择;我运行一个查询从phpmyadmin获取特定数据,然后我试图将这些数据放入XML文件中,但我得到的只是一个空XML文件 另外,我想知道如何使用PHP在XML标记中添加描述? 比如这个 <Exam Number="2" Date="3/7/1433" Time="2 hour" Start="8:30 am" /> PHP代码: <?php $connectdb = mysql_connect('l

我试图根据下拉列表中的用户选择在这里创建一个XML文件, 取决于我的选择;我运行一个查询从phpmyadmin获取特定数据,然后我试图将这些数据放入XML文件中,但我得到的只是一个空XML文件

另外,我想知道如何使用PHP在XML标记中添加描述? 比如这个

<Exam Number="2" Date="3/7/1433" Time="2 hour" Start="8:30 am" />

PHP代码:

<?php
 $connectdb = mysql_connect('localhost','root','sara') or die ("Not Connect");
 if (!$connectdb) die('Could not connect :'. mysql_errno());
 echo "<div align='center' style='direction: ltr' style='position: relative'>
 Choose the exam ID that you want to create it: <br />
  <form action='createxam.php' method='post'> <select name=\"examID\">
  <option value=\"0\">Exam ID </option> \n";
   $selestdb  = mysql_select_db('iexa', $connectdb) or die ("not selected database");
    $qu = mysql_query("SELECT E_No FROM question_bank ") or die ("mysql error");
    while ($row = mysql_fetch_assoc($qu))
    echo "<option value=\"{$row["E_No"]}\">{$row["E_No"]}</option>\n";
  $examID = $_REQUEST['examID'];
    echo "</select> </div> <br /> ";

    echo "The date of the exam : <textarea name:'Date'></textarea><br />
    It will start on (In 24 hours format) : <textarea name:'Start'></textarea><br />
    The time of the exam : <textarea name:'Time'></textarea><br />";
    echo "<div align='center' style='direction: ltr' style='position: relative'>         <input type='submit' value='Create Exam' />
    </form></div>";
    mysql_close($connectdb);
    ?>
save(“mytry.xml”);
if(!mysql_query($sql,$connectdb))
{
die('Error:'.mysql_Error());
}
回显“考试已创建!!”;
回声'

'; mysql_close($connectdb); ?>
下面是我要创建的XML文件:

<?xml version="1.0"?>
<Exams>

 <Exam>
  <Exam Number="1" Date="21/6/1433" Time="1 hour" Start="10:00 am" />
  <Course Name="Graduation Project" Code="CS 492" Credit="3" />
  <Questions ID="1" Type="Multiple-choice" Question="Who has to complete the     Graduation Project?" Choice1="All Student." Choice2="Some student." Choice3="Teacher."     Choice4="Doctor." Correct="All Student." />
  <Questions ID="2" Type="Multiple-choice" Question="When do students begin to work on the Graduation Project?" Choice1="After 2 years from studing." Choice2="Last year." Choice3="High schools" Choice4="Befoer graduation year." Correct="High schools" />
  <Student ID="2853641" Name="Maram Abdullah" password="910" />
  <Student ID="2853615" Name="Maha Al-soyan" password="911" />
 </Exam>

 <Exam>
  <Exam Number="2" Date="3/7/1433" Time="2 hour" Start="8:30 am" />
  <Course Name="Computer Graphics" Code="CS 447" Credit="3" />
  <Questions ID="1" Type="Multiple-choice" Question="........ may be defined as a pictorial representation or graphical representation of objects in a computer." Choice1="GUI" Choice2="Computer graphics." Choice3="represent graphics" Choice4="Computer representation." Correct="Computer graphics." />
  <Questions ID="2" Type="Multiple-choice" Question="What are the advantages of laser printers?" Choice1="High speed, precision and economy." Choice2="Cheap to maintain." Choice3="Quality printers." Choice4="All of the above." Correct="All of the above." />
  <Student ID="2853611" Name="Ro'a Al-turki" password="912" />
  <Student ID="2850742" Name="Sara Al-hejily" password="913" />
 </Exam>

</Exams>

XML不是一门火箭科学。
它与HTML或任何其他格式化文本一样原始。
能够创建HTML表的人当然也能够创建XML。 你不需要花哨的DOM解析器。输出简单的文本

只需获取所需的XML作为示例,并以创建HTML的相同方式创建它

echo "<exam>".htmlspecialchars($exam)."</exam>\n";
echo'.htmlspecialchars($exam)。“\n”;
不比

echo "<td>".htmlspecialchars($exam)."</td>\n";
echo'.htmlspecialchars($exam)。“\n”;

您有
foreach($tests作为$test)
但在代码的前面没有任何地方真正创建变量
$tests
,因此此循环发生0次。。。在循环中,将一个查询中的行放入一个从未使用过的变量
$col
。学会一次做一件事。。。显示表单、查询数据库和生成文档。当你不知道怎么做或者不知道失败在哪里时,不要试图一次完成所有的工作。你的具体问题是什么?我想使用$Exams=mysql\u query(“SELECT*from question\u bank where E\u No=$examID”)中的数据创建一个如上所述的XML文件;但我得到的只是一个空的XML文件!请阅读我的答案,告诉我你的具体问题是什么
echo "<td>".htmlspecialchars($exam)."</td>\n";