Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'ve been working on a payroll management system and this assignment I need hel

ID: 3818979 • Letter: I

Question

I've been working on a payroll management system and this assignment I need help doing the following listed below. What I have done is attached. Thank you
Make the following additions to the e-commerce system you have been developing for your project. The updated e-commerce system should allow your target audience do the followings:
The users should be able to modify records. After the modifications are done, the users should be able to see the changed records on the Web Browser.
The users should be able to delete record(s), which should be accomplished by deleting all related records which may exist in multiple tables
Use the transactions when deleting records from multiple tables, and if at least one of the queries within the same transaction is unsuccessful for some reason, do not execute any of the queries within the same transaction, and if all of the queries in the same transaction are successful, the execute them all
When the records are being shown to the users, sort them using a column or combinatons of more than one column

addEmployee.php x employeeld.php lastinsertedld.php x validateData.php 1 k?php 2 $con mysqu connect ("localhost password"); UserName' 3 if (!$con) die ('Could not connect: mysql error()); 7 mysq select db("databaseName", $con); 9 if (empty POSTI first name])) H 10 echo "Please enter first Name!'; 11 13 if (isset POST[lastnamel)) H echo "Please enter Last Name! 14 15 16 17 $squ INSERT INTO BMPLOYEE(FIRST NAME, LAST NAME, GENDER) VALUES(' POSTlfirstnamel', 's POST [last name] POSTlgender] 18 19 if (!mysqu query ($sql,$con)) 20 ('Error: mysqu error()): die 21 22 23 echo "1 record added": 24 25 mysqu close ($con); 26 27

Explanation / Answer

To modify records:
you will get the modified records from post method, refer below sample code to modify records,

<?php

// Create connection
$conn = new mysqli_connect("localhost", "username", "password");
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
$set_query = '';
if(isset($_POST[firstname]) && $_POST[firstname] != ''){
   $set_query .= "firstname = ".$_POST[firstname];
}
if(isset($_POST[lastname]) && $_POST[lastname] != ''){
   $set_query .= ", lastname = ".$_POST[lastname];
}

/*Update or modify record*/
$sql = "UPDATE employee SET $set_query WHERE employeeId=".$_POST[empid];

if ($conn->query($sql) === TRUE) {
    echo "Record updated successfully";
} else {
    echo "Error updating record: " . $conn->error;
}

/*View modified record*/

$sql = "SELECT * FROM employee WHERE true AND employeeId=".$_POST[empid];
$result = mysqli_query($conn, $sql){
   /*Modify and display it based on your view page*/
   if (mysqli_num_rows($result) > 0) {
       echo "empId: " . $row["empId"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
   }
}

mysqli_close($conn);
?>

Delete records in table:
<?php

// Create connection
$conn = new mysqli_connect("localhost", "username", "password");
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Set autocommit to off, this will start your transaction
mysqli_autocommit($conn,FALSE);

if(isset($_GET[empid]) && $_GET[empid] != ''){
   mysqli_query($conn, "DELETE FROM employee WHERE empId = $_GET[empid]");
}

// Commit transaction, this will end your transaction. If any failure occur during deletion then it won't proceed further and records willl not be deleted.
mysqli_commit($conn);

mysqli_close($conn);
?>

Sort by column:
<?php

// Create connection
$conn = new mysqli_connect("localhost", "username", "password");
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

/*By default it will order by ascending otherwise it will sort based on requirement (ASC or DESC)*/
$order_query = ' firstname ASC';
if(isset($_POST[firstname_type]) && $_POST[firstname_type] != ''){
   $order_query .= "firstname = ".$_POST[firstname_type];
}

$order_query = ', lastname ASC';
if(isset($_POST[lastname_type]) && $_POST[lastname_type] != ''){
   $order_query .= ", lastname = ".$_POST[lastname_type];
}


$sql = "SELECT * FROM employee WHERE true ORDER BY ".$order_query;
$result = mysqli_query($conn, $sql){
   /*Modify and display it based on your view page*/
   if (mysqli_num_rows($result) > 0) {
       echo "empId: " . $row["empId"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
   }
}

mysqli_close($conn);
?>

Note: This is sample code you can change it as per your db name and connections. Since you have used different mysql types like mysqli_query type and mysql_query.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote