简体   繁体   English

XML错误“格式不正确”

[英]XML error 'not well formed'

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.""; 我有一个php文件,该文件返回了一个xml文件,由于以下句子,我收到“格式不正确”的错误: $name_sql= "SELECT * FROM product_description WHERE product_id = ".$id."";

The php file I initialised with: 我初始化的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"?>';

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());

?>

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. XML中的第一行必须是: <?xml version="1.0" encoding="utf-8"?>但是您的include('config.php')可能在它之前输出了一些内容。

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>';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM