Enjoy an ad free experience by logging in. Not a member yet?
Register .
07-25-2012, 05:24 PM
PM User |
#1
New to the CF scene
Join Date: Jul 2012
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
JSON + PHP Help
Hi, this is probably really simple, but i can't get it to work, i need to do a query in PHP / MYSQL based off of the $_GET[] from the URL and then echo it to JSON,
this is what i have
Code:
<?Php
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("ipod") or die(mysql_error());
$query = "SELECT * FROM users WHERE name='". $_GET['name']. "'";
$result = mysql_query($query) or die(mysql_error());
$rows = mysql_fetch_array($result) or die(mysql_error());
echo json_encode($rows);
?>
07-25-2012, 10:47 PM
PM User |
#2
Senior Coder
Join Date: Jan 2011
Location: Missouri
Posts: 2,364
Thanks: 18
Thanked 348 Times in 347 Posts
Your code is good. You maybe using a $_GET['name'] that is wrong. echo out the $query string to see what it is.
07-26-2012, 11:05 PM
PM User |
#3
New to the CF scene
Join Date: Jul 2012
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Ok, can't right now, upgrading database etc ... will let you know
07-26-2012, 11:42 PM
PM User |
#4
New to the CF scene
Join Date: Jul 2012
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Code:
<?Php
mysql_connect("localhost", "root", "e12250") or die(mysql_error());
mysql_select_db("ipod") or die(mysql_error());
$dsn = "mysql:host=localhost;dbname=ipod";
$username = "root";
$password = "e12250";
$query = "SELECT * FROM users WHERE name='". $_GET['name']. "'";
echo $query;
$result = mysql_query($query) or die(mysql_error());
$rows = mysql_fetch_array($result) or die(mysql_error());
echo json_encode($rows);
?>
I did that and it prints nothing ...
07-27-2012, 01:15 PM
PM User |
#5
Senior Coder
Join Date: Jan 2011
Location: Missouri
Posts: 2,364
Thanks: 18
Thanked 348 Times in 347 Posts
So what did the echo $query; print out?
Did you get a name for $_GET['name'] and in your DB is there a name with this 'name'? You can use phpMyAdmin to find out.
07-28-2012, 06:08 PM
PM User |
#6
New to the CF scene
Join Date: Jul 2012
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by
sunfighter
So what did the echo $query; print out?
Did you get a name for $_GET['name'] and in your DB is there a name with this 'name'? You can use phpMyAdmin to find out.
yes, it is there, there is data there, and it is in the url
07-28-2012, 11:16 PM
PM User |
#7
New to the CF scene
Join Date: Jul 2012
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by
emeryc
yes, it is there, there is data there, and it is in the url
whoops, it doesn't print the query$, it is a blank screen
07-29-2012, 07:46 PM
PM User |
#8
New to the CF scene
Join Date: Jul 2012
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Are you still helping?
07-30-2012, 02:42 PM
PM User |
#9
Senior Coder
Join Date: Jan 2011
Location: Missouri
Posts: 2,364
Thanks: 18
Thanked 348 Times in 347 Posts
Your code is good. You maybe using a $_GET['name'] that is wrong. echo out the $query string to see what it is.
Code:
<?Php
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("ipod") or die(mysql_error());
$query = "SELECT * FROM users WHERE name='". $_GET['name']. "'";
echo $query;
$result = mysql_query($query) or die(mysql_error());
$rows = mysql_fetch_array($result) or die(mysql_error());
echo json_encode($rows);
?>
Jump To Top of Thread
Thread Tools
Rate This Thread
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
All times are GMT +1. The time now is 06:29 AM .
Advertisement
Log in to turn off these ads.