Help me to solve the problem


i got error on this program sql_to_xml.php

   <!DOCTYPE html>
  <title>sql to xml convertor</title>
  <form action="" method="POST">
    <input type="text" name='mysql_host' placeholder="Host Name"><br>
    <input type="text" name='mysql_user' placeholder="User Name"><br>
    <input type="text" name='mysql_pass' placeholder="Password"><br>
    <input type="text" name='db_name' placeholder="DataBase Name"><br>
    <input type="text" name='table_name' placeholder="Table Name"><br>
    <input type="submit" value="Sign-in" name="submit" />
//database configuration

//connect to host
//select database
@mysql_select_db($db_name) or die( "Unable to select database");
$xml          = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
$root_element = $table_name."s"; //fruits
$xml         .= "<$root_element>";
//select all items in table
$sql = "SELECT * FROM ".$table_name;
$result = mysql_query($sql);
if (!$result) {
    die('Invalid query: ' . mysql_error());
   while($result_array = mysql_fetch_assoc($result))
      $xml .= "<".$table_name.">";
      //loop through each key,value pair in row
      foreach($result_array as $key => $value)
         //$key holds the table column name
         $xml .= "<$key>";
         //embed the SQL data in a CDATA element to avoid XML entity issues
         $xml .= "$value";
         //and close the element
         $xml .= "</$key>";
//close the root element
$xml .= "</$root_element>";
//send the xml header to the browser
header ("Content-Type:text/xml");
//output the XML data
echo $xml;


What kind of error? :slight_smile:


@ckhawand can you solve this


@ckhawand it showing

error on line 14 at column 10: Opening and ending tag mismatch: br line 0 and form


Try moving all php code to top :slight_smile:


Try using <br /> hopefully this should fix the issue.


Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /storage/ssd1/165/2657165/public_html/xml/sql_to_xml.php:26 Stack trace: #0 {main} thrown in /storage/ssd1/165/2657165/public_html/xml/sql_to_xml.php on line 26

how to fix this?


First of all remove @ from your before all function. Next use either mysqli or pdo extension because mysql extension is deprecated and insecure to use.


In your panel settings you can change PHP to 5.x version and use mysql, but your code is apparently insecure, so I do not recommend using it for professional purposes