Attığınız kodların dışına çıkmadan düzenlemeye çalıştım. Aşağıdaki kodların çalışır olması gerekiyor.
<?php
include ('config.php');
if(isset($_POST['submit'])){
$email = $_POST['email'];
$pword = md5($_POST['password']);
$desig = $_POST['designation'];
$query = $dbh->prepare('INSERT INTO users (`email`, `password`, `designation`) VALUES (?, ?, ?)');
$param = array(
$email,
$pword,
$desig
);
$query->execute($param);
$lastInsertId = $dbh->lastInsertId();
if ($lastInsertId){
echo '<script type="text/javascript">alert("Kayıt Başarılı!");</script>';
echo '<script type="text/javascript">document.location = "index.php";</script>';
}else{
$error = "Bir şeyler ters gitti, lütfen tekrar deneyin.";
}
}