chetan
chetan

Reputation: 41

json encode error in php

I am new to PHP... I have been trying to encode the values retrieved from a MySQL database in JSON and then display the results on a browser..

mysqlcn.php

mysql_connect("127.0.0.1","root","chetan");
mysql_select_db("db1");
$q=mysql_query("SELECT * FROM people WHERE birthyear>'".$_REQUEST['year']."'");
while($e=mysql_fetch_assoc($q))
$output[]=$e;
print(json_encode($output,JSON_FORCE_OBJECT));
mysql_close();

When I try to run it in a browser using address http://localhost/mysqlcn.php, I get this:

{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\froman\fcharset0 
Times New Roman;}{\f1\fswiss\fcharset0 Arial;}} {\*\generator Msftedit 
5.41.15.1507;}\viewkind4\uc1\pard\sb100\sa100\f0\fs24\par \par \f1\fs20\par
\par }

I am currently using WAMP server with PHP 5.3.0

SQL schema

CREATE TABLE people (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
name VARCHAR( 100 ) NOT NULL ,
sex BOOL NOT NULL DEFAULT '1',
birthyear INT NOT NULL)

Upvotes: 1

Views: 896

Answers (2)

Ryan McCue
Ryan McCue

Reputation: 1658

Your output appears to be RTF. Most likely, you have some code which is converting it from HTML to RTF.

Upvotes: 2

lockdown
lockdown

Reputation: 1496

Why do you wish to use JSON to do the display of your database?

PHP can handle this on its own just fine, unless you have a specific reason.

Upvotes: 0

Related Questions