Hola, estoy trabajando en una pagina que esta vinculada a un software que en este caso es un juego en el que se loguean a traves de la pagina osea que si te registraste en la pagina como usuario ej: pepito y tu contraseña; al momento de entrar en el juego coloques lo mismo y entres. Pero para eso necesito que la informacion osea username no se pueda duplicar.
Lo que quiero es que si alguien coloca pepito y ya ese username existe salga "este usuario ya existe". Como lo hago?? aqui esta el codigo de la pagina de registro. registro.php
<?php require_once('Connections/freespace.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
}
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ?
intval($theValue) : "NULL"; break;
case "double":
$theValue = ($theValue != "") ?
doubleval($theValue) : "NULL"; break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); }
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form")) { $insertSQL = sprintf("INSERT INTO usuarios (usuario, nombres, apellidos, contrasena, tipo, dia, mes, ano) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['Usuario'], "text"),
GetSQLValueString($_POST['Nombre'], "text"),
GetSQLValueString($_POST['Apellidos'], "text"),
GetSQLValueString($_POST['Contrasena'], "text"),
GetSQLValueString($_POST['tipo'], "text"),
GetSQLValueString($_POST['dia'], "text"),
GetSQLValueString($_POST['mes'], "text"),
GetSQLValueString($_POST['ano'], "text"));
$insertGoTo = "index.php";
if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ?
"&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING'];
}
}
?>
<!DOCTYPE html>
<html lang="en" class="no-js">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="description" content=""> <meta name="author" content="">
<!-- CSS -->
<link rel='stylesheet' href='http://fonts.googleapis.com/css?family=PT+Sans:400,700'> <link rel="stylesheet" href="assets/css/reset.css"> <link rel="stylesheet" href="assets/css/supersized.css"> <link rel="stylesheet" href="assets/css/style.css">
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<!-- Copyright 2001, 2002, 2003 Macromedia, Inc. All rights reserved. -->
<body bgcolor="#FFFFFF" text="#000000">
<!-- MENU-LOCATION=NONE -->
<div class="page-container"> <h3>Preparate a entrar al mundo de FreeSpace
</h3> <form name="form" action="<?php echo $editFormAction; ?>" method="POST">
<input type="text" name="Nombre" class="nombre" placeholder="Nombre"> <input type="text" name="Apellidos" class="apellidos" placeholder="Apellidos"> <input type="text" name="Usuario" class="username" placeholder="Usuario"> <input type="text" name="E-mail" class="username" placeholder="E-mail"> <input type="password" name="Contrasena" class="password" placeholder="Contraseña">
<h2>Fecha de nacimiento
</h2>
<input type="hidden" name="MM_insert" value="form">
<!-- javascript -->
Mod: Obligatorio el uso de etiquetas GeSHi. Temas sobre PHP van al subforo de PHP. No escribir los títulos en mayúsculas (se considera gritar).