duanmie9682 2014-02-06 18:45 采纳率: 100%
浏览 39

XML错误“形成不良”

i'm having a php file which returns an xml file and I'm getting "Not well formed" error because of the sentence: $name_sql= "SELECT * FROM product_description WHERE product_id = ".$id."";

The php file I initialised with:

header('Content-type: text/xml');
header('Pragma: public');
header('Cache-control: private');
header('Expires: -1');

include('config.php');

echo'<?xml version="1.0" encoding="utf-8"?>';

How can I rewrite that sentence? Thanks

<?php
header('Content-type: text/xml');
header('Pragma: public');
header('Cache-control: private');
header('Expires: -1');

include('config.php');

error_reporting(E_ALL);


function getName($id) {

  $name_sql= "SELECT * FROM product_description WHERE product_id = ".$id."";

  $name_query = mysql_query($name_sql) or die('Eroare nume: '.mysql_error());
  $nume = mysql_fetch_array($name_query);
  return $nume;
}


echo '<?xml version="1.0" encoding="utf-8"?>';
echo '<test>';

$var = mysql_query("SELECT * FROM product order by product_id ASC") or die(mysql_error());
while($var1 = mysql_fetch_array($var)) {
  $nume = getName($var1['product_id']);

  echo '<column><line>'.$nume['name'].'</line></column>';
}


echo '</test>';

<?php

$_CONFIG['db_host'] = 'xyz'; $_CONFIG['db_user'] = 'xyz'; $_CONFIG['db_pass'] = 'xyz'; $_CONFIG['db_name'] = 'xyz';

$_CONFIG['site_URL'] = 'http://xyz.ro';

$lnk = mysql_connect($_CONFIG['db_host'], $_CONFIG['db_user'], $_CONFIG['db_pass']) or die (mysql_error()); mysql_select_db($_CONFIG['db_name'], $lnk) or die (mysql_error());

?>

  • 写回答

1条回答 默认 最新

  • douping3427 2014-02-06 19:26
    关注

    The first line in your XML must be: <?xml version="1.0" encoding="utf-8"?> but your include('config.php') might be outputting something before it.

    Try something like this:

    echo '<?xml version="1.0" encoding="utf-8"?>';
    include('config.php');
    
    function getName($id) {
    
      $name_sql= "SELECT * FROM product_description WHERE product_id = ".$id."";
    
      $name_query = mysql_query($name_sql) or die('Eroare nume: '.mysql_error());
      $nume = mysql_fetch_array($name_query);
      return $nume;
    }
    echo '<test>';
    
    $var = mysql_query("SELECT * FROM product order by product_id ASC") or die(mysql_error());
    while($var1 = mysql_fetch_array($var)) {
      $nume = getName($var1['product_id']);
    
      echo '<column><line>'.$nume['name'].'</line></column>';
    }
    echo '</test>';
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了