Jump to content
shizzzzzzzz

Erros mysqli

Recommended Posts

shizzzzzzzz

Boa noite, eu tenho aqui este código (não foi feito por mim, so editei umas coisas) que é de registo com email activation e quando eu registo e dou submit na página aparece esses erros:

Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in C:\xampp\htdocs\shizzzzzzzz\email_activation\index.php on line 17

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in C:\xampp\htdocs\shizzzzzzzz\email_activation\index.php on line 18

Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in C:\xampp\htdocs\shizzzzzzzz\email_activation\index.php on line 20

<?php
include 'db.php';
$msg='';
if(!empty($_POST['email']) && isset($_POST['email']) &&  !empty($_POST['password']) &&  isset($_POST['password']) )
{
 // username and password sent from Form
 $email=mysql_real_escape_string($_POST['email']);
 $password=mysql_real_escape_string($_POST['password']);

 $regex = '/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/';

 if(preg_match($regex, $email))
 {  
   $password=md5($password); // Encrypted password
   $activation=md5($email.time()); // Encrypted email+timestamp

   $count=mysqli_query($connection,"SELECT uid FROM users WHERE email='$email'");
   if(mysqli_num_rows($count) < 1)
   {
     mysqli_query($connection,"INSERT INTO users(email,password,activation) VALUES('$email','$password','$activation');");

     include 'smtp/Send_Mail.php';
     $to=$email;
     $subject="Email verification";
     $body='Hi, <br/> <br/> We need to make sure you are human. Please verify your email and get started using your Website account. <br/> <br/> <a href="'.$base_url.'activation/'.$activation.'">'.$base_url.'activation/'.$activation.'</a>';
Send_Mail($to,$subject,$body);

     $msg= "Registration successful, please activate email.";

   }
   else
   {
     $msg= '<font color="#cc0000">The email is already taken, please try new.</font>';
   }
 }
 else
 {
   $msg = '<font color="#cc0000">The email you have entered is invalid, please try again.</font>';  
 }
}
?>

ajudem-me :x

Share this post


Link to post
Share on other sites
shizzzzzzzz

ligaste à base de dados? Guardaste a ligação da bd na variável $connection ?

Sim .. :ss

Share this post


Link to post
Share on other sites
N3lson

Tenta assim:


$query = "SELECT uid FROM users WHERE email='".$email."'";

$resultado = mysqli_query($connection, $query);

Edited by N3lson

You can't do it, kid. But don't worry, my boy. You're not the only one. No one else can do it.

Share this post


Link to post
Share on other sites
HappyHippyHippo

Sim .. :ss

então apresenta o código onde validaste que a ligação foi correctamente efectuada


IRC : sim, é algo que ainda existe >> #p@p

Share this post


Link to post
Share on other sites
shizzzzzzzz

então apresenta o código onde validaste que a ligação foi correctamente efectuada

<?php
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', '');
define('DB_DATABASE', 'users');
$connection = @mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
$base_url='http://localhost/email_activation/';
?>

Share this post


Link to post
Share on other sites
HappyHippyHippo

tira o @ antes da chamada da função ... isso serve para ignorar as mensagens de erro e é isso que te falta ... saber qual é o erro.

e para ter ainda mais confirmação :

$connection = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE)
if (mysqli_connect_error()) {
   die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
}


IRC : sim, é algo que ainda existe >> #p@p

Share this post


Link to post
Share on other sites
N3lson

tens aqui um erro

mysqli_query($connection,"INSERT INTO users(email,password,activation) VALUES('$email','$password','$activation');");

ponto e virgula


You can't do it, kid. But don't worry, my boy. You're not the only one. No one else can do it.

Share this post


Link to post
Share on other sites
shizzzzzzzz

Ag ja nao da erros mas sp q registo aparece isso: "The email is already taken, please try new." e nao manda mail para confirmar para o mail q introduzi :x

Share this post


Link to post
Share on other sites
HappyHippyHippo

$count=mysqli_query($connection,"SELECT uid FROM users WHERE email='$email'");
if(mysqli_num_rows($count) < 1)
{
 // ...
}
else
{
 $msg= '<font color="#cc0000">The email is already taken, please try new.</font>';
}

olha bem para o que tens na BD e o email que estás a inserir


IRC : sim, é algo que ainda existe >> #p@p

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.