(Test ending in <4 hours) Cannot add/edit form data but CAN delete data in database. What's up?

Hi all, as my title suggests, I need help with adding data to my database via a form for my practical test (it ends in 4 hours)

These are my codes:

// This is the add.php file, html is omitted

 <?php
	// Check If form submitted, insert form data into announcement table.
	if(isset($_POST['Submit'])) {
		//Obtain data posted from the form
		$id = $_POST['id'];
		$staffNo = $_POST['staffNo'];
		$name = $_POST['name'];
		$email = $_POST['email'];
		$phone = $_POST['phone'];
		
		// include database connection file
		include_once("config.php"); 
				
		// Insert announcement data into table
		$result = mysqli_query($mysqli, "INSERT INTO se_1801362_staff(id,staffNo,name,email,phone) VALUES('$id','$staffNo','$name','$email','$phone','".date("Y-m-d H:i:s")."')");
		
		// Show message when se_1801362_staff added
		echo "Employee added successfully. <a href='index.php'>View Employees</a>";
	}

	?>

// This is the edit.php file, again, html is omitted

 <?php
// include database connection file
include_once("config.php");

// Check if form is submitted for  update, then redirect to homepage after update
if(isset($_POST['update']))
{	
	$id = $_POST['id'];
	
	$staffNo = $_POST['staffNo'];
	$name = $_POST['name'];
	$email = $_POST['email'];
	$phone = $_POST['phone'];
		
	// update se_1801362_staff data
	$result = mysqli_query($mysqli, "UPDATE se_1801362_staff SET id='$id',staffNo='$staffNo',name='$name',email='$email',phone='$phone',posted='".date("Y-m-d H:i:s")."' WHERE id=$id");
	
	// Redirect to homepage to display updated announcement in list
	header("Location: index.php?edit=success");
}
?>
<?php
// Display selected announcement data based on id
// Getting id from url
$id = $_GET['id'];

// Fetch announcement data based on id
$result = mysqli_query($mysqli, "SELECT * FROM se_1801362_staff WHERE id=$id");

$row = mysqli_fetch_assoc($result);

	$staffNo = $row['staffNo'];
	$name = $row['name'];
	$email = $row['email'];
	$phone = $row['phone'];
	$posted = date("Y-m-d H:i:s");

?>

// this is my config.php file

 <?php
/**
 * using mysqli_connect for database connection
 */

$databaseHost = 'localhost';
$databaseUsername = 'root';
$databasePassword = '';
$databaseName = 'se_1801362_db';

$mysqli = mysqli_connect($databaseHost, $databaseUsername, $databasePassword, $databaseName); 
 
?>

I’ve posted this on a PHP server but not getting any replies, i asked some people who finished the test but they’re not responding :confused:

Your timezone is different than mine and this is the earliest I’ve seen the post. It is likely that way for most that answer these questions. You don’t say what issues you are actually having.

Sponsor our Newsletter | Privacy Policy | Terms of Service