0

I'm using the following string to get items from my database:

mysql_query("SELECT * FROM tracking WHERE track_id = '123' ");

I want to get the 123 from the url using a process similar to echo $_GET['id']; so when the url is "http://example.com/?id=456" the string will apear as below:

mysql_query("SELECT * FROM tracking WHERE track_id = '456' ");

Any help would be greatly appreciated.

Gumbo
  • 643,351
  • 109
  • 780
  • 844
  • 1
    Before you actually use any of the suggested solutions, please read [How can I prevent SQL injection in PHP?](http://stackoverflow.com/q/60174/53114) as none of them addressed it. – Gumbo Jan 19 '14 at 11:23
  • Don't use mysql queries, they are deprecated. Use mysqli instead – zurfyx Jan 19 '14 at 11:23

4 Answers4

0

As you already proposed...

mysql_query("SELECT * FROM tracking WHERE track_id = '<?php echo $_GET['id']; ?>' ");

or (since you are probably already in php)...

mysql_query("SELECT * FROM tracking WHERE track_id = '" . $_GET['id'] . "' ");
0

Try this one mysql_query("SELECT * FROM tracking WHERE track_id = '".$_GET['id']."' ");

Jaskaran singh Rajal
  • 2,270
  • 2
  • 17
  • 29
0

mysql_query("SELECT * FROM tracking WHERE track_id = '".$_GET['id']."' ");

Ahmad Hussain
  • 2,443
  • 20
  • 27
0

That'd be a possible approach.
Remember that mysql functions are deprecated (use mysqli instead) and don't forget to sanitize your input.

$id = $_GET['id'];
$id = mysqli_real_escape_string($id);

mysqli_query($db,"SELECT * FROM tracking WHERE track_id = '".$id."' ");
zurfyx
  • 31,043
  • 20
  • 111
  • 145