0

I'm trying to find the correct way of pulling specific field data from a MySQL database. I am using the $_GET but it shows all the data and id. How can I get the data from a specific ID(primary keys).

        echo "<td>" .$view['Absence_Code']."</td>";
        
        echo "<td>" .$view['Details']."</td>";
        
        echo "</tr>";
    
        

2nd File

<body>

<?php
        
    

    $sql = "SELECT * FROM userapproval WHERE ID=$ID";

    $data = mysql_query($sql);
    
?>



</body>
</html>
vvvvv
  • 25,404
  • 19
  • 49
  • 81
user3132907
  • 11
  • 1
  • 4
  • [Please, don't use `mysql_*` functions in new code](http://bit.ly/phpmsql). They are no longer maintained [and are officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the [red box](http://j.mp/Te9zIL)? Learn about [*prepared statements*](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://j.mp/QEx8IB) will help you decide which. If you choose PDO, [here is a good tutorial](http://j.mp/PoWehJ). **You are also wide open to [SQL injections](http://stackoverflow.com/q/60174)** – John Conde Dec 24 '13 at 16:03
  • Your query is hardcoded and doesn't use any $_GET parameters, so it doesn't matter WHAT you pass in to the script - you'll always be running the SAME query. – Marc B Dec 24 '13 at 16:04
  • Basically: `$id = (int)$_GET['id']; $sql = "SELECT * FROM userapproval WHERE Approval = 0 AND ID = $id";` but it's not recommended because it's not safe. Take a look at @JohnConde comment. – Ofir Baruch Dec 24 '13 at 16:06

1 Answers1

1

Add report.php?ID=

 echo "<td>" .'<a href="report.php?ID='.$view['ID'].'">'.$view['ID'].'</a>'."</td>";
Krish R
  • 22,583
  • 7
  • 50
  • 59
  • Thank you user876345! it really helps! forgot to put 'ID'. A lot of thanks too, John Conde, Marc B and Ofir Baruch!! Now I can smile.. hehe – user3132907 Dec 24 '13 at 17:02