Urgent Help Needed: Error # 1096
Posted: Fri Apr 02, 2010 7:32 pm
Hi All
I am using following PHP Code:
This piece of code works fine when fetching only 10 records from database and gives Error # 1096: XML Parse Error as soon as the number of records fetched gets more than 10.
However, this code works perfectly fine on another server.
I am using mysql 5.1.
I would appreciate any pointers that could help me fix this problem.
Best Regards
Vishal
I am using following PHP Code:
Code: Select all
<?php
//query statement to fetch data
$query =
"SELECT
budgetitem as name,
month1,month2,month3,month4,month5,month6,month7,month8,month9,month10,month11,month12,
perchgmon1,perchgmon2,perchgmon3,perchgmon4,perchgmon5,perchgmon6,
perchgmon7,perchgmon8,perchgmon9,perchgmon10,perchgmon11,perchgmon12
FROM
userdata
WHERE
userid = %s";
$query = sprintf($query, quote_smart($_GET['username']));
//execute the query
$result = mysql_query($query, $db) or die(mysql_error($db));
//Get the number of rows
$num_row = mysql_num_rows($result);
//Start the output of XML
echo '<?xml version="1.0" encoding="iso-8859-1"?>';
echo '<userdata>';
echo '<num>' .$num_row. '</num>';
if (!$result) {
die('Query failed: ' . mysql_error());
}
/* get column metadata - column name -------------------------------------------------*/
$i = 0;
while ($i < mysql_num_fields($result)) {
$meta = mysql_fetch_field($result, $i);
$ColumnNames[] = $meta->name; //place col name into array
$i++;
}
$specialchar = array("&",">","<"); //special characters
$specialcharReplace = array("&",">","<"); //replacement
/* query & convert table data and column names to xml ---------------------------*/
$w = 0;
while ($line = mysql_fetch_array($result, MYSQL_NUM)) {
echo '<udata>';
//print_r($line);
foreach ($line as $col_value){
echo '<'.$ColumnNames[$w].'>';
$col_value_strip = str_replace($specialchar, $specialcharReplace, $col_value);
echo $col_value_strip;
//echo $col_value;
echo '</'.$ColumnNames[$w].'>';
if($w == ($i - 1)) { $w = 0; }
else { $w++; }
}
echo '</udata>';
}
if($num_row == "1"){
echo '<udata></udata>';
}
echo '</userdata>';
mysql_free_result($result);
However, this code works perfectly fine on another server.
I am using mysql 5.1.
I would appreciate any pointers that could help me fix this problem.
Best Regards
Vishal