0% found this document useful (0 votes)
50 views4 pages

Dokumen

This PHP code allows users to add new records to a database table by submitting a form that collects their first name, last name, email, and gender. It inserts the submitted data into the "crud" table and redirects on success or shows an error on failure. The form is displayed on an HTML page and includes fields for name, email, and a radio button to select gender, along with submit and cancel buttons.

Uploaded by

Arif Rasyid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views4 pages

Dokumen

This PHP code allows users to add new records to a database table by submitting a form that collects their first name, last name, email, and gender. It inserts the submitted data into the "crud" table and redirects on success or shows an error on failure. The form is displayed on an HTML page and includes fields for name, email, and a radio button to select gender, along with submit and cancel buttons.

Uploaded by

Arif Rasyid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

<?

php

include "db_conn.php";

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

$first_name = $_POST['first_name'];

$last_name = $_POST['last_name'];

$email = $_POST['email'];

$gender = $_POST['gender'];

$sql = "INSERT INTO `crud`(`id`, `first_name`, `last_name`, `email`, `gender`) VALUES


(NULL,'$first_name','$last_name','$email','$gender')";

$result = mysqli_query($conn, $sql);

if ($result) {

header("Location: index.php?msg=New record created successfully");

} else {

echo "Failed: " . mysqli_error($conn);

?>

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">

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

<!-- Bootstrap -->

<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet" integrity="sha384-
rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65"
crossorigin="anonymous">

<!-- Font Awesome -->

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/


all.min.css" integrity="sha512-iecdLmaskl7CVkqkXNQ/ZH/XLlvWZOJyj7Yy7tcenmpD1ypASozpmT/
E0iPtmFIB46ZmdtAc9eNBvH0H/ZpiBw==" crossorigin="anonymous" referrerpolicy="no-referrer" />

<title>PHP CRUD Application</title>

</head>

<body>

<nav class="navbar navbar-light justify-content-center fs-3 mb-5" style="background-color:


#00ff5573;">

PHP Complete CRUD Application

</nav>

<div class="container">

<div class="text-center mb-4">

<h3>Add New User</h3>

<p class="text-muted">Complete the form below to add a new user</p>

</div>

<div class="container d-flex justify-content-center">

<form action="" method="post" style="width:50vw; min-width:300px;">

<div class="row mb-3">

<div class="col">
<label class="form-label">First Name:</label>

<input type="text" class="form-control" name="first_name" placeholder="Albert">

</div>

<div class="col">

<label class="form-label">Last Name:</label>

<input type="text" class="form-control" name="last_name" placeholder="Einstein">

</div>

</div>

<div class="mb-3">

<label class="form-label">Email:</label>

<input type="email" class="form-control" name="email"


placeholder="[email protected]">

</div>

<div class="form-group mb-3">

<label>Gender:</label>

&nbsp;

<input type="radio" class="form-check-input" name="gender" id="male" value="male">

<label for="male" class="form-input-label">Male</label>

&nbsp;

<input type="radio" class="form-check-input" name="gender" id="female" value="female">

<label for="female" class="form-input-label">Female</label>

</div>

<div>

<button type="submit" class="btn btn-success" name="submit">Save</button>

<a href="index.php" class="btn btn-danger">Cancel</a>

</div>

</form>
</div>

</div>

<!-- Bootstrap -->

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7jL+jjXkk+Q2h455rYXK/7HAuoJl+0I4"
crossorigin="anonymous"></script>

</body>

</html>

You might also like