error to appear on the same page
Posted: Mon Apr 27, 2009 7:36 pm
Hi
I have found the codes to detect duplicate primary key, but is there a way for me to make the error appear in the same page, using javascript or the echo value. right now, the form gets an error but it appears on the next page.
and I get the following error
Username already existsError: Duplicate entry 'ss' for key 'PRIMARY'
I want the username already exist to appear on the same page, and do not want the Error: Duplicate entry 'ss' for key 'PRIMARY' to appear at all.
Is there a way.
I have found the codes to detect duplicate primary key, but is there a way for me to make the error appear in the same page, using javascript or the echo value. right now, the form gets an error but it appears on the next page.
Code: Select all
<?php
include('connect.php');
//$Admin_ID=$_POST['Admin_IID'];
$adminname=$_POST['admin_name'];
$username=$_POST['username'];
$password= md5($_POST['password']);
$email_address=$_POST['email_address'];
$department=$_POST['dept_name'];
$URL="/testing/regsuccess-admin.php";
error_reporting(0);
if (isset($_POST['submit']))
{
if (!get_magic_quotes_gpc())
{
$_POST['Admin_ID'] = addslashes($_POST['Admin_ID']);
}
$Admin_ID = $_POST['Admin_ID'];
$check = mysql_query("SELECT Admin_ID FROM administrator WHERE Admin_ID = '$Admin_ID'") or die(mysql_error());
$check2 = mysql_num_rows($check);
if ($check2 != 0)
{
echo 'Username already exists';
}
$insert = "INSERT INTO administrator(Admin_ID, adminname, username, password, email_address, department) VALUES ('$Admin_ID','$adminname','$username','$password','$email_address','$department')";
}
if (!mysql_query($insert))
{
die('Error: ' . mysql_error());
}
header ("Location: $URL");
?>
and I get the following error
Username already existsError: Duplicate entry 'ss' for key 'PRIMARY'
I want the username already exist to appear on the same page, and do not want the Error: Duplicate entry 'ss' for key 'PRIMARY' to appear at all.
Is there a way.