Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question 4 You are going to develop a PHP webpage to insert customer’s email add

ID: 3595440 • Letter: Q

Question

Question 4

You are going to develop a PHP webpage to insert customer’s email address to the server.

Give the MySQL server specification:

Database hostname is ‘192.168.42.160’

Username is ‘dbroot’

Password is ‘dbroot_pwd’

Database name is ‘customerdb’

Table name is ‘emailtbl’


Complete the follwing PHP code.


<?php

// create short variable names
$email=$_POST['email'];

Blank 1 $db = new Blank 2 ('Blank 3', 'dbroot', 'dbroot_pwd', 'Blank 4');

if (mysqli_connect_errno()) {
echo "Error: Could not connect to database. Please try again later.";
Blank 5;
}

$query = "Blank 6 Blank 7 Blank 8 values ('".$email."')";
$Blank 9 = $db->Blank 10 ($query);
if ($result) {
echo $db->affected_rows." email inserted into database.";
} else {
echo "An error has occurred. The item was not added.";
}

$db->close();
?>


Explanation / Answer

// create short variable names
$email=$_POST['email'];

$db = new mysqli ('192.168.42.160', 'dbroot', 'dbroot_pwd', 'customerdb');
if (mysqli_connect_errno()) {
echo "Error: Could not connect to database. Please try again later.";
die("Connection error: " . mysqli_connect_errno());
}
$query = "INSERT INTO customer values ('".$email."')";
$result 9 = $db->query ($query);
if ($result) {
echo $db->affected_rows." email inserted into database.";
} else {
echo "An error has occurred. The item was not added.";
}
$db->close();

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote