CRUD FOTOS PHP METODO MYSQLI
www.rayscoding.com
<!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">
<title>Rays Coding :- PHP Crud Operation</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
<link rel="stylesheet" href="../css/style.css">
</head>
<body>
<div class="container mt-5">
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header bg-dark">
<h4 class="text-center text-light">Rays Coding : PHP CRUD Operation</h4>
</div>
<div class="card-body">
<form action="../insert/insert.php" method="post" enctype="multipart/form-data">
<div class="row">
<div class="col-md-6">
<div class="mb-3">
<label for="username" class="form-label">Name</label>
<input type="text" class="form-control" id="username" name="user_name" placeholder="Enter User Name" autocomplete="off">
</div>
</div>
<div class="col-md-6">
<div class="mb-3">
<label for="useremail" class="form-label">Email</label>
<input type="email" class="form-control" id="useremail" name="user_email" placeholder="Enter Email Address" autocomplete="off">
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="mb-3">
<label for="usercontact" class="form-label">Mobile Number</label>
<input type="text" class="form-control" id="usercontact" name="user_contact" placeholder="Enter Contact Number" autocomplete="off">
</div>
</div>
<div class="col-md-6">
<div class="mb-3">
<label for="userprofile" class="form-label">Profile</label>
<input type="file" class="form-control" id="userprofile" name="user_profile" autocomplete="off">
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="mb-3">
<label for="userpassword" class="form-label">Create Password</label>
<input type="password" class="form-control" id="userpassword" name="user_password" placeholder="Create Password" autocomplete="off">
</div>
</div>
<div class="col-md-6">
<div class="mb-3">
<label for="userpassword" class="form-label">Confirm Password</label>
<input type="password" class="form-control" id="userpassword" name="confirm_user_password" placeholder="Re-Enter Password" autocomplete="off">
</div>
</div>
</div>
<div class="row">
<div class="col-md-6"></div>
<div class="col-md-6">
<button type="submit" name="submit_btn" class="btn bg-dark text-light submit_button"><b>Submit</b></button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
insert.php
<?php
require_once('../connection/conn.php');
if(isset($_POST['submit_btn']))
{
$name = $_POST['user_name'];
$email= $_POST['user_email'];
$contact = $_POST['user_contact'];
$profile = $_FILES['user_profile']['name'];
$profile_temp = $_FILES['user_profile']['tmp_name'];
$profile_location = '../profiles/'.$profile;
$password = $_POST['user_password'];
$confirm_password = $_POST['confirm_user_password'];
if($password == $confirm_password)
{
$insert_data = "INSERT INTO `simple_table`(`name`, `email`, `contact`, `profile`, `password`, `confirm_password`) VALUES ('$name','$email','$contact','$profile','$password','$confirm_password')";
move_uploaded_file($profile_temp, $profile_location);
$insert_query = mysqli_query($conn,$insert_data);
if($insert_query)
{
header('location:../index/index.php');
}
else
{
echo 'Data Not Insert';
}
}
else
{
echo 'Both Password Are Not Matched';
}
}
?>
///////////////////////////////////////////////////////////////////////////
File Name :- edit.php
<?php
require('../connection/conn.php');
$get_id = $_GET['id'];
$select_data_of_user= "SELECT * FROM `simple_table` WHERE id = $get_id";
$select_data_query = mysqli_query($conn, $select_data_of_user);
$selected_fetch_data = mysqli_fetch_array($select_data_query);
?>
<!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">
<title>Rays Coding :- PHP Crud Operation</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
<link rel="stylesheet" href="../css/style.css">
</head>
<body>
<div class="container mt-5">
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header bg-dark d-flex justify-content-between">
<h4 class="text-center text-light">Rays Coding : PHP CRUD Operation</h4>
<a href="../index/index.php" class="btn bg-warning text-dark"><b>Data List</b></a>
</div>
<div class="card-body">
<form action="../update/update.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="user_id" id="" value="<?php echo $selected_fetch_data['id']?>">
<div class="row">
<div class="col-md-6">
<div class="mb-3">
<label for="username" class="form-label">Name</label>
<input type="text" class="form-control" id="username" name="user_name" placeholder="Enter User Name" autocomplete="off" value="<?php echo $selected_fetch_data['name']?>">
</div>
</div>
<div class="col-md-6">
<div class="mb-3">
<label for="useremail" class="form-label">Email</label>
<input type="email" class="form-control" id="useremail" name="user_email" placeholder="Enter Email Address" autocomplete="off" value="<?php echo $selected_fetch_data['email']?>">
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="mb-3">
<label for="usercontact" class="form-label">Mobile Number</label>
<input type="text" class="form-control" id="usercontact" name="user_contact" placeholder="Enter Contact Number" autocomplete="off" value="<?php echo $selected_fetch_data['contact']?>">
</div>
</div>
<div class="col-md-6">
<div class="mb-3">
<label for="userprofile" class="form-label">Profile</label>
<input type="file" class="form-control" id="userprofile" name="user_profile" autocomplete="off" value="">
<img src='../profiles/<?php echo $selected_fetch_data['profile']?>'>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="mb-3">
<label for="userpassword" class="form-label">Create Password</label>
<input type="password" class="form-control" id="userpassword" name="user_password" placeholder="Create Password" autocomplete="off" value="<?php echo $selected_fetch_data['password']?>">
</div>
</div>
<div class="col-md-6">
<div class="mb-3">
<label for="userpassword" class="form-label">Confirm Password</label>
<input type="password" class="form-control" id="userpassword" name="confirm_user_password" placeholder="Re-Enter Password" autocomplete="off" value="<?php echo $selected_fetch_data['confirm_password']?>">
</div>
</div>
</div>
<div class="row">
<div class="col-md-6"></div>
<div class="col-md-6">
<button type="submit" name="update_btn" class="btn bg-dark text-light submit_button"><b>Update</b></button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
File Name :- update.php
<?php
require('../connection/conn.php');
if(isset($_POST['update_btn']))
{
$user_id = $_POST['user_id'];
$name = $_POST['user_name'];
$email = $_POST['user_email'];
$contact = $_POST['user_contact'];
$profile = $_FILES['user_profile']['name'];
$profile_tmp = $_FILES['user_profile']['tmp_name'];
$profile_location = '../profiles/'.$profile;
$password = $_POST['user_password'];
$confirm_password = $_POST['confirm_user_password'];
if(isset($user_id))
{
if($password === $confirm_password)
{
if($profile != '')
{
$update_date = "UPDATE `simple_table` SET `name`='$name',`email`='$email',`contact`='$contact',`profile`='$profile',`password`='$password',`confirm_password`='$confirm_password' WHERE id = $user_id";
$update_date_query = mysqli_query($conn ,$update_date) ;
if($update_date_query)
{
move_uploaded_file($profile_tmp, $profile_location);
header('location:../index/index.php');
}
else
{
echo "<script>alert('Data Not update Successfully'); window.history.back();</script>";
}
}
else
{
$update_date = "UPDATE `simple_table` SET `name`='$name',`email`='$email',`contact`='$contact',`password`='$password',`confirm_password`='$confirm_password' WHERE id = $user_id";
$update_date_query = mysqli_query($conn ,$update_date) ;
if($update_date_query)
{
move_uploaded_file($profile_tmp, $profile_location);
header('location:../index/index.php');
}
else
{
echo "<script>alert('Data Not update Successfully'); window.history.back();</script>";
}
}
else
{
echo "<script>alert('Password Are Not Match'); window.history.back();</script>";
}
}
}
?>
////////////////////////////////////////////////////////////
<?php
$host = 'localhost';
$username = 'root';
$password = '';
$database = 'crud_operation';
$conn = mysqli_connect($host, $username, $password);
mysqli_select_db($conn,$database );
?>
////////////////////////////
<?php
require_once('../connection/conn.php');
?>
<!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">
<title>Rays Coding :- PHP Crud Operation</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css" integrity="sha512-MV7K8+y+gLIBoVD59lQIYicR65iaqukzvf/nwasF0nqhPay5w/9lJmVM2hMDcnK1OnMGCdVK+iQrJ7lzPJQd1w==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<link rel="stylesheet" href="../css/style.css">
</head>
<body>
<div class="container mt-5">
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header bg-dark d-flex justify-content-between">
<h4 class="text-center text-light">Rays Coding : PHP CRUD Operation</h4>
<a href="../form/form.php" class="btn bg-warning text-dark"><b>Add User</b></a>
</div>
<div class="card-body">
<table class="table">
<thead>
<tr>
<th>S No</th>
<th>Name</th>
<th>Email</th>
<th>Contact</th>
<th>Image</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$select_data = "SELECT * FROM `simple_table`";
$select_query = mysqli_query($conn, $select_data);
$rows = mysqli_num_rows($select_query);
if(mysqli_num_rows($select_query)>0)
{
while($row_data = mysqli_fetch_array($select_query))
{
?>
<tr>
<td><?php echo $row_data['id']?></td>
<td><?php echo $row_data['name']?></td>
<td><?php echo $row_data['email']?></td>
<td><?php echo $row_data['contact']?></td>
<td><img src="../profiles/<?php if(isset($row_data['profile'])){echo $row_data['profile']; }?>" alt="profile" width='60' height='60'></td>
<td>
<a href="../edit/edit.php?id=<?php echo $row_data['id'];?>" title='Edit'><i class="fa-solid fa-pen-to-square"></i></a>
<a href="../delete/delete.php?id=<?php echo $row_data['id'];?>" title='Delete'><i class="fa-solid fa-trash"></i></a>
</td>
</tr>
<?php
}
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
</body>
</html>
/////////////////////////////////////////////////
?php
require('../connection/conn.php');
$get_id = $_GET['id'];
$delete_data= "DELETE FROM `simple_table` WHERE `id` = $get_id ";
$delete_data_query = mysqli_query($conn ,$delete_data);
// print_r($delete_data);
if($delete_data_query)
{
header('location:../index/index.php');
}
?>
Comentarios
Publicar un comentario