Jay2391 Posted December 19, 2006 Share Posted December 19, 2006 Okay I am greating a Log in form I can connect to the DB I get all the errors correct with the eception of the email wich is by the way the primary key.Right now when i try to register and i use teh same email address I get this...The query:INSERT INTO user( first_name, last_name, email, password, team, secret ) VALUES ( "Pedro", "Jose", "[email protected]", "96e79218965eb72c92a549dd5a330112", "Cruz", "Hello")Caused the following error: Duplicate entry '[email protected]' for key 1what i will like is something that will tell the customer that the email is already register ...so here is my code hope you can help...I made what i belive was the solution in red....[table][tr][td]<?phpinclude("db.php");$table = 'user'; ini_set ('display_error',1); error_reporting (E_ALL & ~E_NOTICE); define ('Title', 'Register'); //require ('template/header.htlm'); print '<div id="leftcontent"><h1>Registration Form</1h>'; print '<p><h4>Register to check our cool stuff</h4></p>'; print '<h4><form action = "regmain.php" method="post"><p>'; print 'First Name: <input type="text" name="first_name" size"30" value="' . $_POST['first_name'] . '"/><br />'; print 'Last Name: <input type="text" name="last_name" size"30" value="' . $_POST['last_name'] . '"/><br />'; print 'E-Mail: <input type="text" name="email" size"50" value="' . $_POST['email'] . '"/><br />'; print 'Password: <input type="password" name="password" size"50" value="' . $_POST['password'] . '"/><br />'; print 'Confirmation: <input type="password" name="confirm" size"50" value="' . $_POST['confirm'] . '"/><br />'; print 'Team: <input type="text" name="team" size"30" value="' . $_POST['team'] . '"/><br />'; print 'Pin Word: <input type="password" name="secret" size"30" value="' . $_POST['secret'] . '"/><br><br />'; print '<input type="submit" name="submit" size"20" value="Register!!"/><br /></h4>'; $passverf = $_POST['password']; [color=red]$emailverf = $_POST['email']; $tc = mysql_connect ($host, $user, $pass); $db = mysql_select_db ($database, $tc); $query = "SELECT * FROM $table WHERE (email=\"$email\") "; $result = mysql_query($query); $row = mysql_fetch_array($result);[/color] if ( isset ($_POST['submit'])){ $problem = FALSE; //No Issues so far [color=red] [font=Verdana] if($emailverf == $row['email']){ $problem = TRUE; echo "E-Mail is already register"; }[/font] [/color] if (strlen ($passverf) <=5){ $problem = TRUE; print '<p>Your Password must be at least six(6) characters!!!</p>'; } if (empty ($_POST['first_name'])){ $problem = TRUE; print '<p>Please enter your First Name</p>'; } if (empty ($_POST['last_name'])){ $problem = TRUE; print '<p>Please enter your Last Name</p>'; } if (empty ($_POST['email'])){ $problem = TRUE; print '<p>Please enter your E-Mail</p>'; } if (empty ($_POST['password'])){ $problem = TRUE; print '<p>Please enter a Password</p>'; } if ($_POST['password'] != $_POST['confirm']){ $problem = TRUE; print '<p>Your Passwords did not match</p>'; } if (empty ($_POST['confirm'])){ $problem = TRUE; print '<p>Please enter your Password Confirmation</p>'; } if (empty ($_POST['team'])){ $problem = TRUE; print '<p>Please enter your Team Name</p>'; } if (empty ($_POST['secret'])){ $problem = TRUE; print '<p>Please enter your Secret Word</p>'; } $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $email = $_POST['email']; $password = md5($_POST['password']); $confirm = md5($_POST['confirm']); $team = $_POST['team']; $secret = $_POST['secret']; if(!$problem){ $tc = mysql_connect ($host, $user, $pass)or die ("Database is down, try later"); $db = mysql_select_db ($database , $tc); $sql = "INSERT INTO $table ( first_name, last_name, email, password, team, secret ) VALUES ( \"$first_name\", \"$last_name\", \"$email\", \"$password\", \"$team\", \"$secret\")"; $result = mysql_query($sql, $tc) OR die ("The query:".$sql."Caused the following error: ".mysql_error()); print '<p><h4>You are register!, check your E-MAIL for confirmation</h4></p>'; }else{ print '<p><h4>Please try again</h4></p>'; } } ?>[/table] Link to comment https://forums.phpfreaks.com/topic/31285-displaying-message-on-prymary-key-duplication/ Share on other sites More sharing options...
Jay2391 Posted December 19, 2006 Author Share Posted December 19, 2006 Well i took the prymary key of the Database and did this ...but if some has any ideas please shared... $passverf = $_POST['password']; $emailverf = $_POST['email']; $tc = mysql_connect ($host, $user, $pass); $db = mysql_select_db ($database, $tc); $query = "SELECT * FROM $table WHERE (email=\"$emailverf\") "; $result = mysql_query($query); $row = mysql_fetch_array($result); if ( isset ($_POST['submit'])){ $problem = FALSE; //No Issues so far if($emailverf == $row['email']){ $problem = TRUE; echo "E-Mail is already register"; } Link to comment https://forums.phpfreaks.com/topic/31285-displaying-message-on-prymary-key-duplication/#findComment-144772 Share on other sites More sharing options...
esukf Posted December 19, 2006 Share Posted December 19, 2006 You shouldn't really be using an email address as the primary key. Use an auto increment integer instead and a separate column for the email. Think what happens if the user wants to change his email address and you have other tables referencing that user with the email.If you don't want duplicate email addresses, set the email column as unique in the database and when doing an insert/ update check if the email exist first before insert/update like you suggested. Link to comment https://forums.phpfreaks.com/topic/31285-displaying-message-on-prymary-key-duplication/#findComment-144776 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.