I have a database named myshop in MySQL. I am trying to create an html page (http://pastie.org/10568087) where a user enters a first name and then the php page takes that first name and looks for the name in the database and echoes it.
<?php
$firstName = $_POST["firstname"];
try {
$dbh = new PDO('mysql:localhost=localhost;dbname=myshop', "root", "mypassword");
$rows = $dbh->query("SELECT * FROM people WHERE firstname = $firstName");
foreach ($rows as $row) {
echo "First Name: " . $row["first_name"] . "<br/>";
}
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
?>
I can echo all the names when I remove "WHERE firstname = $firstName". But that's not what I want, I just want the name. There is no need to create new input. What's the problem?