Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!