Log in

View Full Version : Resolved help with php pdo mysql



mcolton
06-14-2014, 02:12 PM
What I want to do is run a query based on user input (fname, lname passed from an html program). If I don't find a record, I want to close the database and run a different htm file
Thanks for any help.

This is a piece of my code:


<?php
$fname = filter_input(INPUT_POST, "fname");
$lname = filter_input(INPUT_POST, "lname");

try
{
$connect = new PDO('mysql:host=localhost;dbname=xxxxxx', "xxxxxx", "xxxxxx");
echo 'Connected to database<br />';
$connect->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$sql = "SELECT * FROM contacts WHERE firstname = '$fname' && lastname = '$lname' ";


$connect = null;
}

catch(PDOException $e)
{
echo 'ERROR: ' . $e->getMessage();
}
?>