cs1h Posted September 26, 2007 Share Posted September 26, 2007 Hi, I am using a registration form, which until recently seemed to work, but now I am getting the following error. Could not insert data because Duplicate entry '' for key 2 the script is <?php include("config.php"); $targetb = $_POST['menuFilesDMA']; $targetb = str_replace(' ','_', $targetb); // connect to the mysql server $link = mysql_connect($server, $db_user, $db_pass) or die ("Could not connect to mysql because ".mysql_error()); // select the database mysql_select_db($database) or die ("Could not select database because ".mysql_error()); // check if the username is taken $check = "select id from $table where username = '".$_POST['username']."';"; $qry = mysql_query($check) or die ("Could not match data because ".mysql_error()); $num_rows = mysql_num_rows($qry); if ($num_rows != 0) { echo "Sorry, there the username $username is already taken.<br>"; echo "<a href=register.html>Try again</a>"; exit; } else { // insert the data mysql_query($sql = "insert into `ac_users` (`username`, `password`, `name1`, `email`, `horde`, `origin`) values ('$username', '$password', '$name1', '$day-$month-$year', '$horde', '$targetb')") or die("Could not insert data because ".mysql_error()); // print a success message echo "Your user account has been created!<br>"; echo "Now you can <a href=login.html>log in</a>"; } ?> Does anyone know how to solve this problem, All help is very much appreciated, Thanks Colin Quote Link to comment https://forums.phpfreaks.com/topic/70732-solved-unknown-error/ Share on other sites More sharing options...
HuggieBear Posted September 26, 2007 Share Posted September 26, 2007 My guess would be that one of the other fields in the database (other than the id column) is also set to be unique. Regards Huggie Quote Link to comment https://forums.phpfreaks.com/topic/70732-solved-unknown-error/#findComment-355582 Share on other sites More sharing options...
cs1h Posted September 26, 2007 Author Share Posted September 26, 2007 Hi, I maid that change but now no data is going into the database, it says that the account has been made but nothing is happening. Any ideas why Quote Link to comment https://forums.phpfreaks.com/topic/70732-solved-unknown-error/#findComment-355647 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.