I am starting to learn php PDO because I've read that it is more efficient and secure. I could do the following with simple mysqli but am having trouble making it work with PDO.
PID stands for an id number. fname stands for: first name. lname stands for: last name. age stands for ... age.
Basically I have an index.php that contains links from a test table called "persons" inside of the database drinks. When I click on the link which shows the fname of every row, it goes to insertcarbonated.php which is then supposed to $_GET['fname']; of the link and search up that specific row. However, my code in insertcarbonated.php is not working and I am not familiar enough with PDO to know exactly why, I would like some enlightenment on this because I literally begun learning PDO yesterday. :(
Here is my insertcarbonated.php:
<html>
<?php 
/*** mysql hostname ***/
$hostname = 'localhost';
/*** mysql username ***/
$username = 'theusername';
/*** mysql ***/
$password = 'thepass';
try {
     $dbh = new PDO("mysql:host=$hostname;dbname=drinks", $username, $password);
    /*** echo a message saying we have connected ***/
    echo 'Connected to database';
    /*** The SQL SELECT statement ***/
    $fname = $_GET['fname'];
      //is _GET even working with PDO? 
    $STH = $dbh-> prepare( "SELECT * FROM persons WHERE fname LIKE '$fname'" );
     /***as Joachim suggested, I had actually two different variables here, however, it     
       did not solve the issue **EDITED** from ($DBH to $dbh)****/
    $STH -> execute();
    $result = $STH -> fetch(0);
     //$result should print out the first column correct? which is the person's ID. 
   }
catch(PDOException $e)
   {
   echo $e->getMessage();
   }
?>
<head>
</head>
<body>
 <p><?php print $result; ?></p>
 //me trying to print out person's ID number here. 
</body>
</html>
As previously mentioned, I'm not sure where my error is, I get fatal error: Call to a member function prepare() on a non-object?
and If I try to not use that function, my page is simply blank and nothing prints out. Basically I would just like to print out different bits of information from that row (that is from it's relevant link in index.php). I would like to know how to solve this using PDO.
Here is the previous question I asked, and it was solved but not with PDO. Previous question
 
     
    