Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9

Thread: JSON + PHP Help

  1. #1
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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);
    ?>

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,714
    Thanks
    25
    Thanked 660 Times in 659 Posts
    Your code is good. You maybe using a $_GET['name'] that is wrong. echo out the $query string to see what it is.

  • #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

  • #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 ...

  • #5
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,714
    Thanks
    25
    Thanked 660 Times in 659 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.

  • #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 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

  • #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 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

  • #8
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Are you still helping?

  • #9
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,714
    Thanks
    25
    Thanked 660 Times in 659 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);
    ?>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •