Note that this is on a Linux machine.
I'M just starting to learn PHP and MySQL. I wrote the following php program that executes from an html form. Note that at this point the date from the html form is not being used to query the MySQL database. At this point I'M simply using PHP to display the data entered into the html form to validate that the PHP script is getting the variables from the form, that part is working fine. The second part of the PHP script I'M trying to display a few rows from a simple MySQL database that I've just created. I don't know if my code is bade or if there is something else I need to do in order to link PHP and or Apache to MySQL. Any ideas?
<?php
// get variable from html form
$fName = $_POST['fName'];
$lName = $_POST['lName'];
$phoneNumber = $_POST['phoneNumber'];
$address = $_POST['address'];
$zip = $_POST['zip'];
$state = $_POST['state'];
echo $fName." ";
echo $lName."</p>";
echo $phoneNumber."</p>";
echo $address."</p>";
echo $zip."</p>";
echo $state."</p>";
// Create connection
$con=mysqli_connect("localhost","lrngsql","xyz","bank");
// Check connection
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con, "SELECT fname, lname FROM person");
while($row = mysqli_fetch_array($result))
{
echo $row['fname'] . " " . $row['lname'];
echo "<br />";
}
?>