Urgent Help Needed: Error # 1096

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vishu.gautam
Forum Newbie
Posts: 2
Joined: Fri Apr 02, 2010 7:24 pm

Urgent Help Needed: Error # 1096

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Urgent Help Needed: Error # 1096

Post by requinix »

What's the data for the 11th row?
vishu.gautam
Forum Newbie
Posts: 2
Joined: Fri Apr 02, 2010 7:24 pm

Re: Urgent Help Needed: Error # 1096

Post 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..
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Urgent Help Needed: Error # 1096

Post 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
lunarnet76
Forum Commoner
Posts: 67
Joined: Sun Apr 04, 2010 2:07 pm
Location: Edinburgh

Re: Urgent Help Needed: Error # 1096

Post 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!
Post Reply