dazzathedrummer Posted May 3, 2011 Share Posted May 3, 2011 Hi, This is an odd one (to me anyway). I've created an API for deploying gig information in either XML or JSON format. It works fine as it is, both formats of output giving me what I want. When I take out the mySQL login information and replace it with "include 'connect_include.php';" (where the file connect_include.php contains the exact login code that I replced). The JSON output works fine but the XML output doesn't run. What could be causing this?? JSON API: -http://www.api.the-guards.co.uk/jsontest.php?apikey=123456&format=json XML API: - http://www.api.the-guards.co.uk/jsontest.php?apikey=123456&format=xml API code: <?php if (($_GET['apikey'])==123456 and isset($_GET['format'])){ //Set variables $format = strtolower($_GET['format']); //Connect to the Database include 'connect_include.php'; //Run our query $result = mysql_query(' SELECT * FROM tg_gig_list where gl_date >= curdate() and gl_publish = 1 order by gl_date '); //Preapre our output if($format == 'json') { while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) { $array[] = array($row['gl_date']=>($row['gl_venue'].', '.$row['gl_city'])); }; $output = json_encode($array); //Output the output. echo $output; header('Content-type: application/json'); } elseif($format == 'xml') { header('Content-type: text/xml'); $output = "<?xml version=\"1.0\"?>\n"; $output .= "<tggiglist>\n"; for($i = 0 ; $i < mysql_num_rows($result) ; $i++){ $row = mysql_fetch_assoc($result); $output .= "<giglist> \n"; $output .= "<giglist_date>" . $row['gl_date'] . "</giglist_date> \n"; $output .= "<giglist_venue>" . $row['gl_venue'] . "</giglist_venue> \n"; $output .= "<giglist_city>" . $row['gl_city'] . "</giglist_city> \n"; $output .= "</giglist> \n"; } $output .= "</tggiglist>"; } } else { die ('no way'); } //output the output echo $output; ?> Contents of 'connect_include.php: <?php mysql_connect("database.lcn.com", "dbname", "password") or die(mysql_error()); mysql_select_db("db") or die(mysql_error()); ?> .....this is the same code that I replaced. Obviously, the 'connect' works ok as the JSON version runs fine. There's something being added to the scripting when I use the include file that isn't there when the code goes straight in.....I think???? Quote Link to comment https://forums.phpfreaks.com/topic/235415-php-xlmjson-api-problem-with-mysql-connect-include/ Share on other sites More sharing options...
PFMaBiSmAd Posted May 3, 2011 Share Posted May 3, 2011 Your connect_include.php file probably contains some character(s) before the <?php tag or after the ?> tag or the file was saved as a UTF-8 encoded file with the BOM (Byte Order Mark) character. Insure there is nothing before or after the <?php ?> tags and that the file is saved as an ANSI/ASCII file. Quote Link to comment https://forums.phpfreaks.com/topic/235415-php-xlmjson-api-problem-with-mysql-connect-include/#findComment-1209829 Share on other sites More sharing options...
dazzathedrummer Posted May 3, 2011 Author Share Posted May 3, 2011 Got it!! spaces both before and after!! thanks very much for your help Quote Link to comment https://forums.phpfreaks.com/topic/235415-php-xlmjson-api-problem-with-mysql-connect-include/#findComment-1209838 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.