Jump to content

PHP detects duplicate entry in database


xmuzukerx

Recommended Posts

Hello, i want to make my form detects more than one duplicate entry, my coding here now only detects duplicate username only, how can i make it detects other things not just username only? Can someone fix my code here?

 

<?php
include "db_connect.php";

if( isset( $_SESSION['username'] ) )
{
$username = $_SESSION['username'];
//echo $username;

$result = mysql_query("SELECT * FROM users WHERE username = '$username'",$link) or die ("Database Error");
while ($row = mysql_fetch_assoc($result))
{
$userLevel = $row['userlevel'];
//echo $userLevel;
}

}
?>

<?php
include "db_connect.php";

error_reporting(E_ALL ^ E_NOTICE);

$name = $_POST['name'];
$username = $_POST['username'];
$email = $_POST['email'];
$password = md5 ($_POST['password']);
$matrix = $_POST['matrix'];
$date= date("Y-m-d");
$phone = $_POST['phone'];


//$sql="SELECT matrix FROM registering WHERE matrix='".$_POST['matrix']."'";
//$query= mysql_query($sql);
//$row=mysql_num_rows($query);
if (empty($_POST['matrix'])){
echo 'Please insert matrix number';
}
else{
//if($row == 0){
// echo "No matrix in database...Please contact admin to register<br />";
//}
//else{
$sql2="INSERT INTO users(matrix, name , username , email , password , date , phone)
VALUES ('".$matrix."','".$name."','".$username."','".$email."','".$password."','".$date."', '".$phone."')";
mysql_query($sql2) or die ('<center><h1><font color=red>Error Updating Database! <br>Username already in database!. <br>Please choose another username<br><br><INPUT Type="button" VALUE="Back" onClick="history.go(-1);return true;">');

echo "Registration Successful!<br />";
echo "Please go to [<a href='index.php'>Main Page</a>] to login..";
}
//}

?>
Link to comment
https://forums.phpfreaks.com/topic/275549-php-detects-duplicate-entry-in-database/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.