MySQL Form
PHP and MySQL
I created this web form for CSIS 2440 Web Programming. Using it, you can create new records that are stored in the database, update existing records, and search for a record.
Here's the PHP script I wrote to create a new record in the friends table. I also wrote scripts to search and update records using SELECT and UPDATE statements.
// Store POST variables in variables $firstName =
$_POST["FirstName"]; $lastName = $_POST["LastName"]; $phoneNum =
$_POST["PhoneNum"]; $address = $_POST["Address"]; $city =
$_POST["City"]; $state = $_POST["State"]; $zipcode =
$_POST["ZipCode"]; $bdate = $_POST["Bdate"]; $userName =
$_POST["UserName"]; $pword = $_POST["Password"]; $sex =
$_POST["Sex"]; $relationship = $_POST["Relationship"]; $servername =
"208.117.38.17"; $username = "terimotj_root"; $password = "*****";
$dbname = "terimotj_Friends"; $tbl = "friends"; // Create connection
to the database $conn = new mysqli($servername, $username,
$password, $dbname); // Check connection if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error); } //echo
"Connected successfully<br>"; //Create a record $query =
"INSERT INTO $tbl (`FirstName`, `LastName`, `PhoneNum`, `Address`,
`City`, `State`, `ZipCode`, `Bdate`, `UserName`, `Password`, `Sex`,
`Relationship`) VALUES" . "('" . $firstName ."', '$lastName',
'$phoneNum', '$address', '$city', '$state', $zipcode, '$bdate',
'$userName', '$pword', '$sex', '$relationship')"; $return =
mysqli_query($conn, $query) or die (mysqli_error($conn)); $row=
mysqli_fetch_array($return); echo "<h2>" . $firstName . " " .
$lastName . " was added successfully.</h2><br>";