Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-25-2012, 05:24 PM   PM User | #1
emeryc
New to the CF scene

 
Join Date: Jul 2012
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
emeryc is an unknown quantity at this point
Post 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);
?>
emeryc is offline   Reply With Quote
Old 07-25-2012, 10:47 PM   PM User | #2
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,364
Thanks: 18
Thanked 348 Times in 347 Posts
sunfighter is on a distinguished road
Your code is good. You maybe using a $_GET['name'] that is wrong. echo out the $query string to see what it is.
sunfighter is offline   Reply With Quote
Old 07-26-2012, 11:05 PM   PM User | #3
emeryc
New to the CF scene

 
Join Date: Jul 2012
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
emeryc is an unknown quantity at this point
Ok, can't right now, upgrading database etc ... will let you know
emeryc is offline   Reply With Quote
Old 07-26-2012, 11:42 PM   PM User | #4
emeryc
New to the CF scene

 
Join Date: Jul 2012
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
emeryc is an unknown quantity at this point
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 ...
emeryc is offline   Reply With Quote
Old 07-27-2012, 01:15 PM   PM User | #5
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,364
Thanks: 18
Thanked 348 Times in 347 Posts
sunfighter is on a distinguished road
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.
sunfighter is offline   Reply With Quote
Old 07-28-2012, 06:08 PM   PM User | #6
emeryc
New to the CF scene

 
Join Date: Jul 2012
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
emeryc is an unknown quantity at this point
Quote:
Originally Posted by sunfighter View Post
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
emeryc is offline   Reply With Quote
Old 07-28-2012, 11:16 PM   PM User | #7
emeryc
New to the CF scene

 
Join Date: Jul 2012
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
emeryc is an unknown quantity at this point
Quote:
Originally Posted by emeryc View Post
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
emeryc is offline   Reply With Quote
Old 07-29-2012, 07:46 PM   PM User | #8
emeryc
New to the CF scene

 
Join Date: Jul 2012
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
emeryc is an unknown quantity at this point
Are you still helping?
emeryc is offline   Reply With Quote
Old 07-30-2012, 02:42 PM   PM User | #9
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,364
Thanks: 18
Thanked 348 Times in 347 Posts
sunfighter is on a distinguished road
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);
?>
sunfighter is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:29 AM.


Advertisement
Log in to turn off these ads.