Hola que tal necesito ayuda, con un código de registro en php, el error que me tira es el siguiente: "Warning: mysql_affected_rows() [function.mysql-affected-rows]: A link to the server could not be established in C:\wamp\www\index.php on line 58"
La linea 58 es esta :
if(mysql_affected_rows()==1) {
Ahora el código completo:
<?php
if (isset($_POST['submitted'])) {
$errors = array ();
require_once ('mysql_connect.php');
}
if (eregi('^[[:alnum:]\.\'\-]{4,30}$', stripslashes(trim($_POST['username']))) ) {
$user= mysql_real_escape_string($_POST['username']);
$query="SELECT username FROM users WHERE username = '$user'";
$result=mysql_query($query);
$num=mysql_num_rows($result);
if($num> 0) {
$errors[] = '<font color="red">The username you have chosen has already been taken, please try again.</font>';
} else {
$username =mysql_real_escape_string($_POST['username']);
}
} else {
$errors[]='<font color="red">Please provide a valid username between 4 and 30 characters.</font>';
}
if (!eregi('^[a-zA-Z]+[a-zA-Z0-9_-]*@([a-zA-Z0-9]+){1}(\.[a-zA-Z0-9]+)
{1,2}', stripslashes(trim($_POST['email'])) )) {
$errors[]= '<font color="red">Please provide a valid email adress.</font>';
} else {
$email=mysql_real_escape_string($_POST['email']);
}
if(!empty($_POST['password1'])) {
if($_POST['password1'] != $_POST['password2']){
$errors[]='<font color="red">The 2 passwords you have entered do not match.</font>';
} else {
$password=$_POST['password1'];
}
} else {
$errors[]='<font color ="red">Please provide a password.</font>';
}
if(empty($errors)) {
$a=md5(uniqid(rand(),true));
$query="INSERT INTO users (username, email, password, active) VALUES ('$username','$email', SHA('$password'), '$a')";
$result= mysql_query($query);
}
if(mysql_affected_rows()==1) {
//Send the E-Mail
$body="Thank you for registering at the User Registration Site.To activate your account, please click on this link:\n\n";
$body.="http://www.whateveraddressyouwantthere.com/activate.php?x=" . mysql_insert_id() . "&y=$a";
mail($_POST['email'], 'Registration Confirmation', $body, 'From:contactoweb@writeme.com');
//Show thank message
echo '<h3>Thank You!</h3>
You have been registered, you have been sent an e-mail to the address you specified before.Please check your e-mails to activate your
account. ';
} else {
echo '<font color="red">You could not be registered, please contact us about the problem and we will fix it as soon as we can.</font>';
}
?>
<html>
<head>
</head>
<body>
<h3>Register</h3>
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
<p><input type="text" name="username" value="<?php if (isset($_POST['username'])) echo $_POST['username']; ?>" size="30" maxlenght="30" />
<small>Username</small></p>
<p><input type="password" name="password1" size="30" maxlenght="40" />
<small>Password</small></p>
<p><input type="password" name="password2" size="30" maxlenght="40" />
<small>Confirm Password</small></p>
<p><input type="text" name="email" size="30" maxlenght="30" value="<?php if(isset($_POST['mail'])) { echo $_POST['mail']; } ?>" /> <small> Email Address</small></p>
<p><input type="submit" name="submit" value="Register" /></p>
<input type="hidden" name="submitted" value="TRUE" />
</form>
</body>
</html>
Gracias de antemano.
Hola, prueba de pasarle como parámetro, el resultado de la consulta.
...
$result= mysql_query($query);
}
if(mysql_affected_rows($result)==1) {
...
Hola hice lo que me recomendaste, pero me tira el siguiente error: "Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in C:\wamp\www\index.php on line 58 ".
Que puedo hacer?
Gracias por responder
mira, no conozco esa funcion, pero que tal si haces esto:
<?php
if (isset($_POST['submitted'])) {
$errors = array ();
require_once ('mysql_connect.php');
}
if (eregi('^[[:alnum:]\.\'\-]{4,30}$', stripslashes(trim($_POST['username']))) ) {
$user= mysql_real_escape_string($_POST['username']);
$query="SELECT username FROM users WHERE username = '$user'";
$result=mysql_query($query);
$num=mysql_num_rows($result);
if($num> 0) {
$errors[] = '<font color="red">The username you have chosen has already been taken, please try again.</font>';
} else {
$username =mysql_real_escape_string($_POST['username']);
}
} else {
$errors[]='<font color="red">Please provide a valid username between 4 and 30 characters.</font>';
}
if (!eregi('^[a-zA-Z]+[a-zA-Z0-9_-]*@([a-zA-Z0-9]+){1}(\.[a-zA-Z0-9]+)
{1,2}', stripslashes(trim($_POST['email'])) )) {
$errors[]= '<font color="red">Please provide a valid email adress.</font>';
} else {
$email=mysql_real_escape_string($_POST['email']);
}
if(!empty($_POST['password1'])) {
if($_POST['password1'] != $_POST['password2']){
$errors[]='<font color="red">The 2 passwords you have entered do not match.</font>';
} else {
$password=$_POST['password1'];
}
} else {
$errors[]='<font color ="red">Please provide a password.</font>';
}
if(empty($errors)) {
$a=md5(uniqid(rand(),true));
$query="INSERT INTO users (username, email, password, active) VALUES ('$username','$email', SHA('$password'), '$a')";
$result= mysql_query($query);
}
if(!mysql_error) {
//Send the E-Mail
$body="Thank you for registering at the User Registration Site.To activate your account, please click on this link:\n\n";
$body.="http://www.whateveraddressyouwantthere.com/activate.php?x=" . mysql_insert_id() . "&y=$a";
mail($_POST['email'], 'Registration Confirmation', $body, 'From:contactoweb@writeme.com');
//Show thank message
echo '<h3>Thank You!</h3>
You have been registered, you have been sent an e-mail to the address you specified before.Please check your e-mails to activate your
account. ';
} else {
echo '<font color="red">You could not be registered, please contact us about the problem and we will fix it as soon as we can.</font>';
}
?>
<html>
<head>
</head>
<body>
<h3>Register</h3>
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
<p><input type="text" name="username" value="<?php if (isset($_POST['username'])) echo $_POST['username']; ?>" size="30" maxlenght="30" />
<small>Username</small></p>
<p><input type="password" name="password1" size="30" maxlenght="40" />
<small>Password</small></p>
<p><input type="password" name="password2" size="30" maxlenght="40" />
<small>Confirm Password</small></p>
<p><input type="text" name="email" size="30" maxlenght="30" value="<?php if(isset($_POST['mail'])) { echo $_POST['mail']; } ?>" /> <small> Email Address</small></p>
<p><input type="submit" name="submit" value="Register" /></p>
<input type="hidden" name="submitted" value="TRUE" />
</form>
</body>
</html>
me parece mas practyico ;) suerte y contame omo te va...
que paciencia tomi, eso si que no lo peudo hacer. ajaja
saludos desde san martin de los andes!
Cita de: cɐstg en 25 Enero 2010, 00:48 AM
mira, no conozco esa funcion, pero que tal si haces esto:
<?php
if (isset($_POST['submitted'])) {
$errors = array ();
require_once ('mysql_connect.php');
}
if (eregi('^[[:alnum:]\.\'\-]{4,30}$', stripslashes(trim($_POST['username']))) ) {
$user= mysql_real_escape_string($_POST['username']);
$query="SELECT username FROM users WHERE username = '$user'";
$result=mysql_query($query);
$num=mysql_num_rows($result);
if($num> 0) {
$errors[] = '<font color="red">The username you have chosen has already been taken, please try again.</font>';
} else {
$username =mysql_real_escape_string($_POST['username']);
}
} else {
$errors[]='<font color="red">Please provide a valid username between 4 and 30 characters.</font>';
}
if (!eregi('^[a-zA-Z]+[a-zA-Z0-9_-]*@([a-zA-Z0-9]+){1}(\.[a-zA-Z0-9]+)
{1,2}', stripslashes(trim($_POST['email'])) )) {
$errors[]= '<font color="red">Please provide a valid email adress.</font>';
} else {
$email=mysql_real_escape_string($_POST['email']);
}
if(!empty($_POST['password1'])) {
if($_POST['password1'] != $_POST['password2']){
$errors[]='<font color="red">The 2 passwords you have entered do not match.</font>';
} else {
$password=$_POST['password1'];
}
} else {
$errors[]='<font color ="red">Please provide a password.</font>';
}
if(empty($errors)) {
$a=md5(uniqid(rand(),true));
$query="INSERT INTO users (username, email, password, active) VALUES ('$username','$email', SHA('$password'), '$a')";
$result= mysql_query($query);
}
if(!mysql_error) {
//Send the E-Mail
$body="Thank you for registering at the User Registration Site.To activate your account, please click on this link:\n\n";
$body.="http://www.whateveraddressyouwantthere.com/activate.php?x=" . mysql_insert_id() . "&y=$a";
mail($_POST['email'], 'Registration Confirmation', $body, 'From:contactoweb@writeme.com');
//Show thank message
echo '<h3>Thank You!</h3>
You have been registered, you have been sent an e-mail to the address you specified before.Please check your e-mails to activate your
account. ';
} else {
echo '<font color="red">You could not be registered, please contact us about the problem and we will fix it as soon as we can.</font>';
}
?>
<html>
<head>
</head>
<body>
<h3>Register</h3>
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
<p><input type="text" name="username" value="<?php if (isset($_POST['username'])) echo $_POST['username']; ?>" size="30" maxlenght="30" />
<small>Username</small></p>
<p><input type="password" name="password1" size="30" maxlenght="40" />
<small>Password</small></p>
<p><input type="password" name="password2" size="30" maxlenght="40" />
<small>Confirm Password</small></p>
<p><input type="text" name="email" size="30" maxlenght="30" value="<?php if(isset($_POST['mail'])) { echo $_POST['mail']; } ?>" /> <small> Email Address</small></p>
<p><input type="submit" name="submit" value="Register" /></p>
<input type="hidden" name="submitted" value="TRUE" />
</form>
</body>
</html>
me parece mas practyico ;) suerte y contame omo te va...
Buenisimo, muchas gracias por la ayuda. Gracias!!!
Me olvidaba, lo probé pero el warning que me tira es el siguiente:
"Deprecated:Function eregi() is deprecated in C:\wamp\www\activation.php on line 11"
"Deprecated: Function eregi() is deprecated in C:\wamp\www\activation.php on line 33"
Alguna sugerencia?
intenta con preg_match
Cita de: den_22 en 25 Enero 2010, 03:43 AM
Me olvidaba, lo probé pero el warning que me tira es el siguiente:
"Deprecated:Function eregi() is deprecated in C:\wamp\www\activation.php on line 11"
"Deprecated: Function eregi() is deprecated in C:\wamp\www\activation.php on line 33"
Alguna sugerencia?
Te esta diciendo que ereg es obsoleta xD por lo menos en la ultima version de php, en el comienzo del documento pon_
<?php
error_reporting(0);
...
Con eso no te mostrara errores
Muchas gracias, por haberme contestado.