Foros del Web » Programando para Internet » PHP »

Php registro de usuarios

Estas en el tema de Php registro de usuarios en el foro de PHP en Foros del Web. OLaa me podieis indicar q esta mal en esta archivo de regsitro.php: <?php include("config.php"); // connect to the mysql server $link = mysql_connect($server, $db_user, $db_pass) ...
  #1 (permalink)  
Antiguo 26/12/2012, 09:13
 
Fecha de Ingreso: mayo-2012
Mensajes: 363
Antigüedad: 11 años, 10 meses
Puntos: 0
Php registro de usuarios

OLaa me podieis indicar q esta mal en esta archivo de regsitro.php:


<?php

include("config.php");

// 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
$insert = mysql_query("insert into $table values ('NULL', '".$_POST['username']."', '".$_POST['password']."', '".$_POST['name1']."', '".$_POST['name2']."', '".$_POST['hotmail ']."', '".$_POST['website']."', 'images/avatar.jpg')")
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>";
}

?>


han abrirlo con dreamweaver me sale esto:

"; echo "Try again"; exit; } else { // insert the data $insert = mysql_query("insert into $table values ('NULL', '".$_POST['username']."', '".$_POST['password']."', '".$_POST['name1']."', '".$_POST['name2']."', '".$_POST['hotmail ']."', '".$_POST['website']."', 'images/avatar.jpg')") or die("Could not insert data because ".mysql_error()); // print a success message echo "Your user account has been created!
"; echo "Now you can log in"; } ?>

el fallo que tiene es q me sale todo el echo y lo de insertare en la tabla,seguro q es una tonteria pero no digo con ello alguien me ayuda.

un saludo y muchas gracias
  #2 (permalink)  
Antiguo 26/12/2012, 12:12
Avatar de homlyne  
Fecha de Ingreso: noviembre-2012
Ubicación: Madrid
Mensajes: 59
Antigüedad: 11 años, 4 meses
Puntos: 10
Respuesta: Php registro de usuarios

Hola santi2892009,

Pero te refieres cuando se abre en navegador?, y cuando lo abres, en la barra de direcciones del navegador como aparece la url file://tu-pagina.php o http://localhost/tu-pagina.php?
__________________
_________________________

Homlyne - Soporte Online
  #3 (permalink)  
Antiguo 26/12/2012, 13:08
 
Fecha de Ingreso: mayo-2012
Mensajes: 363
Antigüedad: 11 años, 10 meses
Puntos: 0
Respuesta: Php registro de usuarios

si mira tengo un registro de usuarios php y lo habro en localhost:
tengo:
login.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>User Login</title>
<style type="text/css">
body {
background-repeat: no-repeat;
background-image: url(../warofdesert1/login/tanque.jpg);
}
</style>
</head>
<script type="text/javascript">
function setFocus(aField) {
document.forms[0][aField].focus();
}

function isAnEmailAddress(aTextField) {

if (document.forms[0][aTextField].value.length<5) {
return false;
}
else if (document.forms[0][aTextField].value.indexOf("@") < 1) {
return false;
}
else if (document.forms[0][aTextField].value.length -
document.forms[0][aTextField].value.indexOf("@") < 4) {
return false;
}
else { return true; }
}

function isEmpty(aTextField) {
if ((document.forms[0][aTextField].value.length==0) ||
(document.forms[0][aTextField].value==null)) {
return true;
}
else { return false; }
}

function validate() {
if (isEmpty("username")) {
alert("Please fill your username.");
setFocus("username");
return false;
}
if (isEmpty("password")) {
alert("Please fill in your password.");
setFocus("password");
return false;
}
return true;
}
</script>
<body>
<form action="login.php" method="post" onSubmit="return validate()">
<p><strong>Register</strong></p>
<p>Username:
<input type="text" name="username" size="20">
<br>
Password:
<input type="password" name="password" size="20">
<br>
<input type="submit" value="Log In">
| <a href="register.html">Register a new account</a>
</form>
<form action="forgotpass.php" method="post">
<p><strong>Forgot Password</strong></p>
<p>Username:
<input type="text" name="username" size="20"></p>
<input type="submit" value="Re-Send">
</form>
</body>
</html>
resgistro.php-----
<?php

include("config.php");

// 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
$insert = mysql_query("insert into $table values ('NULL', '".$_POST['username']."', '".$_POST['password']."', '".$_POST['name1']."', '".$_POST['name2']."', '".$_POST['hotmail ']."', '".$_POST['website']."', 'images/avatar.jpg')")
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>";
}

?>
----------------------fortpass.php-----
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Forgot Password</title>
</head>

<body>

<?php
$username = $_POST['username'];

include "config.php";
mysql_connect($server, $db_user, $db_pass) or die (mysql_error());
$result = mysql_db_query($database, "select * from $table WHERE username = '$username'") or die (mysql_error());

while ($qry = mysql_fetch_array($result)) {
// echo "$qry[email]";
// echo "$qry[password]";

$sendto = $qry[email];

$mymail = "$sendto";
$cc = 'Requested Password';
$FrOm = "$sendto";
$BoDy = '';
$BoDy .= "Dear ";
$BoDy .= $_POST['username'];
$BoDy .= "\n";
$BoDy .= "\n";
$BoDy .= "Forgotten password request";
$BoDy .= "\n";
$BoDy .= 'A request was made to resend your password to this address, if you did not request this password request please report it to the website administrator';
$BoDy .= "\n";
$BoDy .= "\n";
$BoDy .= 'Your password is:';
$BoDy .= "\n";
$BoDy .= $qry[password];
$BoDy .= "\n";

$send = mail("$mymail", "$cc", "$BoDy", "From: $FrOm");
if($send)
{
echo 'An Email has been sent successfully to your email address with your forgotten password, please allow up to a hour for the email to arrive.<br><br><a href="login.html">Login</a>';
}

}
?>
</body>
</html>
---------------config.php----------
<?php
// Server to connect to, the default is 'LocalHost' but if it does not work use your IP address for your server
$server = "localhost";

// The name of the database, when using cPanel you would normally have your user name first like so: username_DATABASE-NAME
$database = "phpavanzado";

// MySQL username to access the database with.
$db_user = "root";

// MySQL password to access the database with.
$db_pass = "";

// The table that this script will set up and use, you can change this but recommended to keep the same so if you require any support we can help faster
$table = "primero";
?>
------------members.php-----------

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Members' Section</title>
</head>

<body>

<p>

<!--- Members Page Code Start --->
<?php
$username = $_COOKIE['loggedin'];
if (!isset($_COOKIE['loggedin'])) die("You are not logged in, <a href=login.html>click here</a> to login.");
echo "You are logged in $username";
?>
<!--- Members Page Code End --->

|

<!--- Profile Link Code Start --->
<a href="members/profile.php">Profile</a>
<!--- Profile Link Code End --->

|

<!--- Logout Code Start --->
<a href="logout.php">Logout</a>
<!--- Logout Code End --->

</p>

<!--- Demo Stuff Start --->
<p>To see demo members page with all features please <a href="members/index.php">click here</a></p>
<!--- Demo Stuff End --->

</body>
</html>

----------un register.htm----
<html>
<head>
<title>User Registration</title>
</head>
<script type="text/javascript">
function setFocus(aField) {
document.forms[0][aField].focus();
}

function isAnEmailAddress(aTextField) {

if (document.forms[0][aTextField].value.length<5) {
return false;
}
else if (document.forms[0][aTextField].value.indexOf("@") < 1) {
return false;
}
else if (document.forms[0][aTextField].value.length -
document.forms[0][aTextField].value.indexOf("@") < 4) {
return false;
}
else { return true; }
}

function isEmpty(aTextField) {
if ((document.forms[0][aTextField].value.length==0) ||
(document.forms[0][aTextField].value==null)) {
return true;
}
else { return false; }
}
function validate() {

if (isEmpty("username")) {
alert("Please fill your username.");
setFocus("username");
return false;
}
if (isEmpty("password")) {
alert("Please fill in your password.");
setFocus("password");
return false;
}
if (!isAnEmailAddress("email")) {
alert("The entered email address is invalid.");
setFocus("email");
return false;
}
return true;

}
</script>
<body>

<form action="register.php" method="post" onSubmit="return validate()">
<p>Username: *<br />
<input type="text" name="username" size="20">
<br>
Password: *<br />
<input type="password" name="password" size="20">
<br>
First Name:<br />
<input type="text" name="name1" size="20">
<br>
Second Name:<br />
<input type="text" name="name2" size="20">
<br>
Email: *<br />
<input type="text" name="email" size="20">
<br>
Website: (Please add http://)<br />
<input type="text" name="website" size="20">
<br>
<input type="submit" value="Sign Up">
</p>
</form>
<br />
Note: Marked * are required
</body>
</html>
-------un validar usuario.php
<?php session_start();

//datos para establecer la conexion con la base de mysql.
mysql_connect('localhost','usuario','password')or die ('Ha fallado la conexi&oacute;n: '.mysql_error());
mysql_select_db('mi_base')or die ('Error al seleccionar la Base de Datos: '.mysql_error());

function quitar($mensaje)
{
$nopermitidos = array("'",'\\','<','>',"\"");
$mensaje = str_replace($nopermitidos, "", $mensaje);
return $mensaje;
}

if(trim($HTTP_POST_VARS["usuario"]) != "" && trim($HTTP_POST_VARS["password"]) != "")
{
// Puedes utilizar la funcion para eliminar algun caracter en especifico
//$usuario = strtolower(quitar($HTTP_POST_VARS["usuario"]));
//$password = $HTTP_POST_VARS["password"];
// o puedes convertir los a su entidad HTML aplicable con htmlentities
$usuario = strtolower(htmlentities($HTTP_POST_VARS["usuario"], ENT_QUOTES));
$password = $HTTP_POST_VARS["password"];
$result = mysql_query('SELECT password, usuario FROM usuarios WHERE usuario=\''.$usuario.'\'');
if($row = mysql_fetch_array($result)){
if($row["password"] == $password){

$_SESSION["k_username"] = $row['usuario'];

echo 'Has sido logueado correctamente '.$_SESSION['k_username'].' <p>';
echo '<a href="index.php">Index</a></p>';

//Elimina el siguiente comentario si quieres que re-dirigir autom&aacute;ticamente a index.php

/*Ingreso exitoso, ahora sera dirigido a la pagina principal.
<SCRIPT LANGUAGE="javascript">
location.href = "index.php";
</SCRIPT>*/

}else{
echo 'Password incorrecto';
}
}else{
echo 'Usuario no existente en la base de datos';
}
mysql_free_result($result);
}else{
echo 'Debe especificar un usuario y password';
}
mysql_close();
?>
esto es un sistema de login,registro y olvido su contraseña....
el tema q cuando relleno el register.html,me sale al dar al boton raro me sale el codigo entero

Etiquetas: html, mysql, registro, tabla, usuarios
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 23:47.