this is my connection to database:
<?php
$servername = "localhost";
$user = "root";
$pass = "mhimlaA#1";
$conn = new PDO("mysql:host=$servername;dbname=mydb", $user, $pass);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
//echo "Connected successfully";
function read($where = '')
{
global $conn;
$sql = "SELECT * FROM `form` $where LIMIT 1000;";
$stm = $conn->prepare($sql);
$stm->execute();
return $stm->fetchAll(PDO::FETCH_ASSOC);
}
and this my store my where the user enter his data to the DB:
<?php
//print_r($_POST);
include 'db.php';
$sql = "INSERT INTO mydb.form(username, password, email) VALUES (:username,:password,:email)";
$stm = $conn->prepare($sql);
$stm->execute($_POST);
header('location: index.php');
i want to handle the duplication error for username and password and send message to user?