Jump to content

Erros mysqli


shizzzzzzzz
 Share

Recommended Posts

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

Link to comment
Share on other sites

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/';
?>
Link to comment
Share on other sites

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
Link to comment
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
 Share

×
×
  • 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.