Help me to solve the problem


#1

i got error on this program sql_to_xml.php

   <!DOCTYPE html>
<html>
<head>
  <title>sql to xml convertor</title>
</head>
<body>
  <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" />
  </form>
<?php
if(isset($_POST["submit"])){
//database configuration
$mysql_host=$_POST['mysql_host'];
$mysql_user=$_POST['mysql_user'];
$mysql_pass=$_POST['mysql_pass'];
$db_name=$_POST['db_name'];
$table_name=$_POST['table_name'];

 
//connect to host
mysql_connect($mysql_host,$mysql_user,$mysql_pass);
//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());
}
 
if(mysql_num_rows($result)>0)
{
   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>";
      }
 
      $xml.="</".$table_name.">";
   }
}
//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;
}
?>
  </body>
</html>

#2

What kind of error? :slight_smile:


#3

@ckhawand can you solve this


#4

@ckhawand it showing

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


#5

Try moving all php code to top :slight_smile:


#6

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


#7

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?


#8

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.


#10

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