Ver Mensaje Individual
  #1 (permalink)  
Antiguo 29/01/2010, 09:57
rtr
 
Fecha de Ingreso: abril-2009
Mensajes: 368
Antigüedad: 15 años
Puntos: 2
porque me da este error...??

En un sistema de registro si alguien se quiere registrar cn un nombre ya registrado ,devuelve este error ;

Could not insert data because Duplicate entry 'jesus' for key 2

Traducido;

No se pudo insertar los datos, porque jesus Duplicate entry 'para 2 claves

Cita:
<?php
error_reporting(0);
session_start();
include("config.php");
//echo $_SESSION['tmptxt']." == ".$_POST['letras'];
if($_SESSION['tmptxt']==$_POST['letras']){
//echo "son iguales";
// 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 email = '".$_POST['email']."';";
$qry = mysql_query($check)
or die ("Could not match data because ".mysql_error());
$num_rows = mysql_num_rows($qry);
if ($num_rows != 0) {
echo "Lo sentimos, ya existe una cuenta con este email; <strong>".$_POST['email']."</strong>.<br> ¡solo puede tener una cuenta!<br> ";
echo "<a href=register.html>Volver</a>";
exit;
} else {
// insert the data
$insert = mysql_query("insert into $table values ('NULL', '".$_POST['username']."', '".$_POST['password']."', '".$_POST['name1']."', '".$_POST['name2']."', '".$_POST['email']."', '".$_POST['website']."', 'images/avatar.jpg')")
or die("Could not insert data because ".mysql_error());

$contenido='<strong>Bienvenido/a </strong><br><br> <strong>sus datos de acceso:</strong><br><br> <strong>Email:</strong>'.' '.$_POST['email'].'<br><strong>Contraseña:</strong>'.' '.$_POST['password'];
$cabeceras = 'MIME-Version: 1.0' . "\r\n";
$cabeceras .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$cabeceras .= 'From: [email protected]';
$asunto="Sus datos de registro";
$para=$_POST['email'];
$controlar=mail($para,$asunto,$contenido,$cabecera s);
// print a success message
echo "Su cuenta de usuario ha sido creada!<br>";
echo "Puede acceder <a href=login.html>aquí</a> <br> ";
}
} else{
header("Location:register.html?error=mal");
}
?>