Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Displaying one row's details from a url (mysql/php)

Options
  • 30-01-2017 2:26pm
    #1
    Registered Users Posts: 1,459 ✭✭✭


    Hi all, i am new to php/mysql but i am just making a small project to help me learn it, i have a "people" page with a list of fictitious people and various details... i then have their name or id hyperlinked to a profile page so when you click the hyperlink it goes to this address....

    http://127.0.0.1/profile.php?id=77

    what do i need to change in the select script to make it take the id 77 from the url as the id (or whatever id i decide to click on...) in the following select statement?
    $result = mysql_query("SELECT * FROM people where id=?????????") 
    or die(mysql_error());
    


    Thanks and sorry if its a really stupid question but i am only learning

    H


Comments

  • Registered Users Posts: 1,459 ✭✭✭Heathen


    I figured it out...

    I put
    $id = $_GET['id'];
    
    into my php

    and then changed the select statement to
    $result = mysql_query("SELECT * FROM people where id=$id") 
    or die(mysql_error());
    

    and its now referencing the individual id's when i click on them :)

    Happy days


  • Registered Users Posts: 6,252 ✭✭✭Buford T Justice


    Heathen wrote: »
    I figured it out...

    I put
    $id = $_GET['id'];
    
    into my php

    and then changed the select statement to
    $result = mysql_query("SELECT * FROM people where id=$id") 
    or die(mysql_error());
    

    and its now referencing the individual id's when i click on them :)

    Happy days

    Understand why this is actually happening and what $_GET is and it will help you a lot more also.


  • Moderators, Computer Games Moderators Posts: 4,281 Mod ✭✭✭✭deconduo


    Understand why this is actually happening and what $_GET is and it will help you a lot more also.

    And then read up on SQL injection.


  • Registered Users Posts: 6,150 ✭✭✭Talisman


    @Heathen : The mysql_query() function was deprecated in PHP 5.5 (released in 2013) which reaches its end-of-life in terms of support in a few months time. The function no longer exists in the latest version of PHP.

    You must be using a well out of date resource to learn which is never a good thing especially in the realm of PHP. Find a better/more up to date one. Use PHP The Right Way as your reference. If you are only beginning to learn PHP you may as well start by learning what are considered the best practices.

    PHP Data Objects (PDO) is the recommended way to access a database in PHP.

    Here are a couple of tutorials to get you started:
    Why you Should be using PHP's PDO for Database Access
    PHP Database Access: Are You Doing It Correctly?

    Using Prepared Statements will get you around the SQL Injection issue.


Advertisement