<?php
error_reporting(-1);//Первый файл для добавления юзеров.
include 'connect.php';///trim olmalidir loginde,unikal olmalidir, name -login eyni deyil.
if (isset($_POST['send'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$mobile = $_POST['mobile'];
$password = $_POST['password'];
$ins = mysqli_query($connect,"INSERT into crud (name,email,mobile,password) VALUES('$name','$email','$mobile','$password')");
//$name,$email,$mobile,$password
if ($ins) {
header('Location: display.php');
}else{
echo 'something wrong';
}
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Crud operation</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">
</head>
<body>
<div class="container mb-5">
<form method="post" action="users.php">
<div class="mb-3">
<label>Name</label>
<input type="text" class="form-control" name="name">
</div>
<div class="mb-3">
<label>Email</label>
<input type="email" class="form-control" name="email">
</div>
<div class="mb-3">
<label>Mobile</label>
<input type="text" class="form-control" name="mobile">
</div>
<div class="mb-3">
<label>Password</label>
<input type="text" class="form-control" name="password">
</div>
<hr>
<button type="submit" class="btn btn-primary" name="send">Submit</button>
</form>
</div>
</body>
</html>
<?php
error_reporting(-1); //Второй файл для того чтобы прочесть, а также добавить кнопкой юзера.
include "connect.php";
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Crud operation</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">
</head>
<body>
<div class="container">
<button class="btn btn-primary my-5"><a href="users.php" class="text-light">Add User</a></button>
<table class="table">
<thead>
<tr>
<th scope="col">Serial number</th>
<th scope="col">Name</th>
<th scope="col">Email</th>
<th scope="col">Mobile</th>
<th scope="col">Password</th>
<th scope="col">Operations</th>
</tr>
</thead>
<tbody>
<?php
$sel = mysqli_query($connect,"SELECT * FROM `crud`");
if ($sel) {
while($row= mysqli_fetch_assoc($sel)) {
$id=$row['id'];
$name=$row['name'];
$email=$row['email'];
$mobile=$row['mobile'];
$password=$row['password'];
?>
<tr>
<td><?=$id;?></td>
<td><?=$name;?></td>
<td><?=$email?></td>
<td><?=$mobile;?></td>
<td><?=$password;?></td>
<td><button class="btn btn-primary"><a href="update_form.php?updateid=<?=$id;?>"class="text-light">Update</a></button> <button class="btn btn-danger"><a href="delete.php?deleteid=<?=$id;?>" class="text-light">Delete</a></button></td>
</tr>
<?php
}
}
?>
</tbody>
</table>
</div>
</body>
</html>
<?php
error_reporting(-1); //Файл для Update, где собственно и проблема
include 'connect.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Update</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">
</head>
<body>
<?php
if(isset($_POST['updateid'])) {
$id = $_POST['updateid'];
$name = $_POST['name'];
$email =$_POST['email'];
$mobile =$_POST['mobile'];
$password =$_POST['password'];
$sel = mysqli_query($connect, "SELECT * FROM crud WHERE id = '$id'");
$row = mysqli_fetch_assoc($sel);
if ($row) {
$update = mysqli_query($connect,"UPDATE crud SET /*id= '$id',*/ name = '$name', email = '$email', mobile='$mobile',password ='$password' WHERE id='$id'");
}
if($update) {
echo 'Updated successfully';
}else {
exit(mysqli_error($update));
}
}
?>
<form method="post" action="update_form.php">
<input type="hidden" class="form-control" name="updateid" value="<?=$row['id']?>">
<div class="mb-3">
<label>Name</label>
<input type="text" class="form-control" name="name" value="<?=$row['name']?>">
</div>
<div class="mb-3">
<label>Email</label>
<input type="email" class="form-control" name="email" value="<?=$row['email']?>">
</div>
<div class="mb-3">
<label>Mobile</label>
<input type="text" class="form-control" name="mobile" value="<?=$row['mobile']?>">
</div>
<div class="mb-3">
<label>Password</label>
<input type="text" class="form-control" name="password" value="<?=$row['password']?>">
</div>
<hr>
<button type="submit" class="btn btn-primary" name="send">Submit</button>
</form>
</div>
</body>
</html>
</body>
</html>