Page 1 of 1

Urgent Help Needed: Error # 1096

Posted: Fri Apr 02, 2010 7:32 pm
by vishu.gautam
Hi All

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

Re: Urgent Help Needed: Error # 1096

Posted: Fri Apr 02, 2010 7:35 pm
by requinix
What's the data for the 11th row?

Re: Urgent Help Needed: Error # 1096

Posted: Sun Apr 04, 2010 3:24 pm
by vishu.gautam
The data in the 11th row is same as the data in other rows.. nothing different. I tried with even copying data from other rows..

Re: Urgent Help Needed: Error # 1096

Posted: Sun Apr 04, 2010 3:47 pm
by Eran
All the rows hold the same data? that doesn't make sense.
In any case, you should use htmlentities() instead of a custom special characters function

Re: Urgent Help Needed: Error # 1096

Posted: Sun Apr 04, 2010 7:40 pm
by lunarnet76
ok your code is supposed to work, I tried it with a different SQL query and it worked, so the problem must come from your SQL query!