xmuzukerx Posted March 12, 2013 Share Posted March 12, 2013 (edited) 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.."; } //} ?> Edited March 12, 2013 by ignace Please, use code tags not quote tags. Quote Link to comment https://forums.phpfreaks.com/topic/275549-php-detects-duplicate-entry-in-database/ Share on other sites More sharing options...
shlumph Posted March 12, 2013 Share Posted March 12, 2013 my coding here now only detects duplicate username only I do not see how your code detects this. It is your DB table definition, with a UNIQUE index on the username column? Quote Link to comment https://forums.phpfreaks.com/topic/275549-php-detects-duplicate-entry-in-database/#findComment-1418177 Share on other sites More sharing options...
xmuzukerx Posted March 12, 2013 Author Share Posted March 12, 2013 I do not see how your code detects this. It is your DB table definition, with a UNIQUE index on the username column? yes, Quote Link to comment https://forums.phpfreaks.com/topic/275549-php-detects-duplicate-entry-in-database/#findComment-1418178 Share on other sites More sharing options...
shlumph Posted March 12, 2013 Share Posted March 12, 2013 Why not just put a unique index on other fields? Quote Link to comment https://forums.phpfreaks.com/topic/275549-php-detects-duplicate-entry-in-database/#findComment-1418183 Share on other sites More sharing options...
xmuzukerx Posted March 12, 2013 Author Share Posted March 12, 2013 can i know how to put it? sorry still newbie Quote Link to comment https://forums.phpfreaks.com/topic/275549-php-detects-duplicate-entry-in-database/#findComment-1418185 Share on other sites More sharing options...
AyKay47 Posted March 12, 2013 Share Posted March 12, 2013 Any field that is to be unique should be properly indexed. This will allow you to use ON DUPLICATE KEY UPDATE or possibly INSERT IGNORE Quote Link to comment https://forums.phpfreaks.com/topic/275549-php-detects-duplicate-entry-in-database/#findComment-1418186 Share on other sites More sharing options...
shlumph Posted March 12, 2013 Share Posted March 12, 2013 can i know how to put it? sorry still newbie http://lmgtfy.com/?q=mysql+set+unique+index Quote Link to comment https://forums.phpfreaks.com/topic/275549-php-detects-duplicate-entry-in-database/#findComment-1418189 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.