Question
my code works but i have to refresh the page to show results, how do i fix that? week7.php function insertPersons(){ val = $(#firstname).val(); val2
my code works but i have to refresh the page to show results, how do i fix that?
week7.php
week7ajax.php
' ); define( 'DB_USER', '
$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); ?>
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