Question
Can't get functions to work. Should be able to verify if user exists and then successfully add a new user with this Ajax/Jquery program. 1.
Can't get functions to work. Should be able to verify if user exists and then successfully add a new user with this Ajax/Jquery program.
1. Enter at least three rows of data into
EMAIL (40)
ADDRESS(100) PHONE VARCHAR(10)
2. Create a HTML form that contains three input fields and an update button. After user enters an email in the email field, the form auto populates other fields. Display a message asks if user needs to update the information. If so, use can update the information (After user hits the Update button, display a message saying your information has been updated. Keep other parts on the screen as it is) . Do all these using AJAX/JQuery.
--------index.html-------
User Profile
---------lookup.php--------
$servername = "localhost"; $username = "icoolsho_dcoulte"; $password = "$!980-49-2554"; $dbname = "icoolsho_dcoulter";
?>
------update.php-----
include 'db.php';
// Get the data that's being written to the database.
$post_data = json_decode(file_get_contents('php://input'), true);
$email = $post_data['email'];
$address = $post_data['address'];
$phone = $post_data['phone'];
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die(json_encode(array("error" => "database fail: " . $conn->connect_error)));
}
// Delete the old record from the database if there was one
$sql = "DELETE FROM Assignment9 WHERE email='" . $email . "'";
if ($conn->query($sql) != TRUE) {
die(json_encode(array("error" => "could not delete old record: " . $conn->error)));
}
// Insert the new record into the database
$sql = "INSERT INTO Assignment9 (email, address, phone) VALUES ( "
. "'" . $email . "',"
. "'" . $address . "',"
. "'" . $phone . "')";
if ($conn->query($sql) === TRUE) {
die(json_encode(array("error" => "Update successful!")));
} else {
die(json_encode(array("error" => "could not update record: " . $conn->error)));
}
?>
------db.php-------
$servername = ""; $username = ""; $password = ""; $dbname = "";
?>
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started