我有一个php文件,它返回一个xml文件,因为这句话我得到“Not well formed”错误:
$name_sql= "SELECT * FROM product_description WHERE product_id = ".$id."";
我初始化的php文件:
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"?>';
我怎样才能改写那句话?感谢
<?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());
?>
答案 0 :(得分:0)
XML中的第一行必须是:<?xml version="1.0" encoding="utf-8"?>
,但您的include('config.php')
可能会在其之前输出内容。
尝试这样的事情:
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>';