Question

Project 6-2: Manage technicians For this project, youll create an application that lets an admin user view and delete existi

- php

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi,

Here is the HTML and PHP code for above operations.

In this I've taken the sno from database as a auto incrementing unique key for deleting purpose. If you want to delete by name or email you can replace sno with email wherever it occured.

index.php

<?php

//connection for connect to the database in php with mysql

$conn = mysqli_connect("localhost", "root", "your_password");

mysqli_select_db($conn, "database_name");

?>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<meta http-equiv="X-UA-Compatible" content="ie=edge">

<title>SportsPro</title>

<style>

body {

margin: 0;

}

table {

border: 1px solid black;

border-collapse: collapse;

}

td,

th {

border: 1px dotted black;

padding: 3px;

}

a {

font-size: 16px;

font-weight: bold;

text-decoration: 1px solid black;

}

table,

a,

span,

p {

margin-left: 30px;

}

span {

font-size: 20px;

font-weight: bold;

}

form{

display: inline; margin: 0;

}

</style>

</head>

<body>

<span>

SportsPro Technical Support

</span>

<p>

Sports management software for the sports enthusiast

</p>

<a href="#">Home</a>

<div style="border: 1px solid black;width: 100%;"></div>

<br />

<span>Technician List</span>

<table>

<tr>

<th>

First Name

</th>

<th>

Last Name

</th>

<th>

Email

</th>

<th>

Phone

</th>

<th>

Password

</th>

<th>

</th>

</tr>

<?php

//displaying the data from database

$query1 = mysqli_query($conn, "SELECT * FROM technicians");

while ($res = mysqli_fetch_array($query1)) {

echo "<tr>";

echo "<td>" . $res['first_name'] . "</td>";

echo "<td>" . $res['last_name'] . "</td>";

echo "<td>" . $res['email'] . "</td>";

echo "<td>" . $res['phone'] . "</td>";

echo "<td>" . $res['password'] . "</td>";

//form for delete action

echo "<td>

<form action='index.php' method='post'>

<input type='hidden' name='sno' value='" . $res['sno'] . "'>

<input type='submit' name='delete' value='Delete' />

</form>

</td>";

echo "</tr>";

}

?>

</table>

<br />

<!-- Hyper link for going to the page for Adding Technician -->

<a href="add_technician.php">Add Technician</a>

<div style="border: 1px solid black;width: 100%;margin-top: 30px;"></div>

<?php

//php code for deleting the technician

if (isset($_POST['delete'])) {

$sno = $_POST['sno'];

echo $sno;

$query2 = mysqli_query($conn, "DELETE FROM technicians where sno='$sno'");

if($query2){

echo "<script>alert('Technician Details Deleted');window.location.href='index.php'</script>";

}

}

?>

</body>

</html>

add_technician.php

<?php

//connection for connect to the database in php with mysql

$conn = mysqli_connect("localhost", "root", "your_password");

mysqli_select_db($conn, "database_name");

?>

<?php

//connection for connect to the database in php with mysql

$conn = mysqli_connect("localhost", "root", "your_password");

mysqli_select_db($conn, "");

?>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<meta http-equiv="X-UA-Compatible" content="ie=edge">

<title>Add Technician</title>

<style>

div{

width: 100%;

}

label{

width: 200px;

}

form{

border: 1px solid black;

padding: 10px;

width: 200px;

}

</style>

</head>

<body>

<h3>Add Technician Details</h3>

<form action="add_technician.php" method="post" enctype="multipart/form-data">

<div>

<label style="width: 300px">

First Name:

</label>

<input type="text" name="first_name" />

</div>

<div>

<label>

Last Name:

</label>

<input type="text" name="last_name" />

</div>

<div>

<label>

Email:

</label>

<input type="text" name="email" />

</div>

<div>

<label>

Phone:

</label>

<input type="text" name="phone" />

</div>

<div>

<label>

Password:

</label>

<input type="password" name="password" />

</div>

<br/>

<input type="submit" value="Add Technician" name="add_technician"/>

</form>

<?php

//storing the data came from the form

//isset will triggered when only some post action got

if(isset($_POST["add_technician"])){

$first_name = $_POST["first_name"];

$last_name = $_POST["last_name"];

$email = $_POST["email"];

$phone = $_POST["phone"];

$password = $_POST["password"];

$insertQuery = mysqli_query($conn, "INSERT INTO technicians(first_name, last_name, email, phone, password) values('$first_name','$last_name','$email','$phone','$password')");

if($insertQuery){

echo "<script>alert('Technician Details addedd Successfully!!!');window.location.href='index.php'</script>";

//after successful adding technician, the page will go to home page.

}else{

echo "<b>Some thing error while inseting data. Check the errors</b>";

}

}

?>

</body>

</html>

Screenshot(s):

SportsPro Technical Support Sports management software for the sports enthusiast Home Technician List First Name Last Name Em

Add Technician Details First Name: Last Name: Email: Phone: Password: Add Technician

If you have any doubts, please comment under this answer.

Thank you!!!

We were unable to transcribe this image

Add Technician Details First Name: Last Name: Email: Phone: Password: Add Technician

Add a comment
Know the answer?
Add Answer to:
- php Project 6-2: Manage technicians For this project, you'll create an application that lets an...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT