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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

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

  • 30-01-2017 1:26pm
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 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, Registered Users 2 Posts: 6,262 ✭✭✭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,282 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, Registered Users 2 Posts: 6,284 ✭✭✭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