mcolton
06-14-2014, 07:52 PM
I need help with the following. User inputs his fname and lname. Program finds that record in a MySQL database.
Display the data fields on a html form and allow the user to update any of the fields. User then hits submit button and changes are made and database is closed.
I'm new to PDO and am having a hard time understanding it. Thanks for any help
<?php
$fname = filter_input(INPUT_POST, "fname"); // from previous html program
$lname = filter_input(INPUT_POST, "lname"); // from previous html program
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();
}
?>
Display the data fields on a html form and allow the user to update any of the fields. User then hits submit button and changes are made and database is closed.
I'm new to PDO and am having a hard time understanding it. Thanks for any help
<?php
$fname = filter_input(INPUT_POST, "fname"); // from previous html program
$lname = filter_input(INPUT_POST, "lname"); // from previous html program
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();
}
?>