This the connection using PDO
<?php
session_start();
include 'db_config.php';
try {
$conn = new PDO("mysql:host=localhost;dbname=$database","root","");
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// prepare sql and bind parameters
$stmt = $conn->prepare("INSERT INTO users (name, username,
password)
VALUES (:name, :username, :password)");
$stmt->bindParam(':name', $name);
$stmt->bindParam(':username', $username);
$stmt->bindParam(':password', $password);
// insert a row
$name = $_POST["name"];
$username = $_POST["username"];
$password = $_POST["password"];
$stmt->execute();
$query="select * from users";
$d = $conn->query($query);
}
catch(PDOException $e)
{
echo "Error: " . $e->getMessage();
}
$conn = null;
?>
This is the user registration form
<form method="post">
<div class="modal-body">
<div class="form-group">
<input type="text" name="username" placeholder="Enter Username" class="form-control">
<br>
<br>
<input type="text" name="name" placeholder="Enter Name" class="form-control">
<br>
<br>
<input type="password" name="password" placeholder="Enter Password" class="form-control">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary" name="save_user">Save changes</button>
</div>
</form>
This is the Table
<tbody>
<?php foreach ($d as $data)
{
?>
<tr>
<td><?php echo $data['users_id']?></td>
<td><?php echo $data['username']?></td>
<td><?php echo $data['name']?></td>
</tbody>
</tr>
<?php
}
?>
This image is the User Registration Form
This image after clicking the Save button in my User Registration Form
This image after clicking the "reload button" in chrome
Hello Everyone, How to fix this kind of error. The Scenario is if the Admin wants to register another user so that the admin is going to click the button for the user registration form once the admin clicked the button the admin need to fill out the form then once the admin finishes the form then click the SAVE button to save the data in "IMAGE "2". Imagine the data is saved so that when the user clicked the reload page in chrome the Previous data duplicates "IMAGE 3". How to prevent this? Sorry, I'm Beginner in PHP :)