Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

my website code isnt working how can i fix it? week7ajax.php week7.php function Insertperson() { val = $(#firstname).val(); val2 = $(#lastname).val2(); val3 = $(#telephonenumber).val3(); $.get(./week7ajax.php,{cmd:

my website code isnt working how can i fix it?

week7ajax.php

' ); define( 'DB_USER', '' ); define( 'DB_PASSWORD', '' ); define( 'DB_HOST', 'localhost' );

$conn = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // Check connection if (!$conn) { die("Connection failed: " . mysqli_connect_error()); }

function DeletePersonEntry($id) { global $conn; $del = "DELETE FROM people WHERE id = '$id' "; $result = $conn->query($del); }

function InsertPerson($firstname, $lastname, $telephonenumber) { global $conn; $insert = "INSERT INTO people (firstname, lastname, telephonenumber) VALUES ('$firstname', '$lastname', '$telephonenumber')"; $result = $conn->query($insert); }

function showPeople() { global $conn;

$sql = "SELECT id, firstname, lastname, telephonenumber FROM people"; $result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) { // output data of each row while($row = mysqli_fetch_assoc($result)) { $id = $row["id"]; $delurl = "[delete]"; echo "id: " . $row["id"]. " - First name: " . $row["firstname"]. " Last name: " . $row["lastname"]. " Telephone number: " . $row["telephonenumber"]. " $delurl "; } } else { echo "0 results"; } }

$cmd = $_GET['cmd'];

if ($cmd == 'create') { InsertPerson($_GET['firstname'], $_GET['lastname'], $_GET['telephonenumber']); } else if($cmd == 'delete') { $id = $_GET['id']; DeletePersonEntry($id); } showPeople(); mysqli_close($conn);

?>

week7.php

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database Administration The Essential Reference

Authors: Brian Laskey, David Kreines

1st Edition

1565925165, 978-1565925168

More Books

Students also viewed these Databases questions