I've build a php page called pageById.php that pulls in and displays data from a MySQL database, but the query is 'static'.

$sql = "SELECT * FROM table WHERE id = 879";

I want to change this so it uses a variable in-place of 879.

$sql = "SELECT * FROM table WHERE id = $var";

I'd like to be able to pull the $var from a link on the previous page or from the URL, but I'm not sure how.

Can someone please help or point me in the direction of a decent tutorial for beginners?


  • 1
    Questions about programming websites are a better fit for StackOverflow. Without the request for a tutorial this could be moved there. Jan 18, 2017 at 22:52

1 Answer 1


You need to learn about GET and POST variables.

This is really basic PHP stuff :P

Have a look at http://php.net/manual/en/reserved.variables.post.php

This question is likely to be migrated to Stack Overflow where I am almost certain it will be a duplicate question

Not the answer you're looking for? Browse other questions tagged or ask your own question.