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
Código
<?php require_once('Connections/freespace.php'); ?> <?php function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": break; case "double": break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $editFormAction = $_SERVER['PHP_SELF']; } $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"; $insertGoTo .= $_SERVER['QUERY_STRING']; } } ?>
Código
<!DOCTYPE html> <html lang="en" class="no-js"> <head> <meta charset="utf-8"> <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. --> </head> <body bgcolor="#FFFFFF" text="#000000"> <!-- MENU-LOCATION=NONE --> <div class="page-container"> <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"> </select> <select name="mes"> </select> <select name="ano"> <input type="hidden" name="MM_insert" value="form"> </form> <div class="connect"> </div> </div> <!-- javascript --> </body> </html>
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).