Jump to content

Need some little help here


snsz

Recommended Posts

when i log in here i get this error:

icmkqe.jpg

 

I've been struggling to this for more than 2 days and i cannot fix it :(

 

Here's the code:

 

<?php 

if(isset($_SESSION['user'])){
session_destroy(); }

if(isset($_POST['enviar'])){


session_start(); 
include('db_mysql.php'); 
$md5 = md5($_POST['passe']); 
$query=mysql_query("SELECT * FROM utilizadores WHERE username = '$_POST[user]' and 
password = '$md5'");
/** $query=mysql_query("SELECT * FROM utilizadores WHERE username = '$_POST[user]' and 
password = '$md5'") or die(mysql_error());  **/

$total = mysql_num_rows($query); 
if ($total != 0){

$linha = mysql_fetch_array($query); 
if($linha['ativo'] == 0){
$erro = "Utilizador não existe ou não esta ativo"; 
echo "<script> window.alert('$erro');</script>";
echo "<script> window.location =\"index.php?erro=$erro\"; </script>"; 
}
else {
$_SESSION['user'] = $linha['username'];
$_SESSION['numero'] = $linha['id_utilizador']; 
$_SESSION['nome'] = $linha['nome']; 
echo "<script> window.location =\"pagina.php\"; </script>";
}
}
}

include('footer.php');

?>

  this is the index.php,

and this is the db_mysql.php that it includes:

 

<?php 
$db=mysql_connect("localhost","root","") or die("Impossivel ligar ao servidor mysql");
mysql_select_db("bd_ti",$db);

$sql="select * from utilizadores";
$rs=mysql_query($sql);    //odbc_exec ---> mysql_query
while ($row=mysql_fetch_row($rs))
{
$id=$row[0];   //campo 0 da tabela utilizadores
$username=$row[1]; //campo 1 ...
$password=$row[2];
$nome=$row[3]; 
$activo=$row[4];
$hash=$row[5];
$email=$row[6];


}
//echo $username;

mysql_close($db);


$caminho ="http://localhost/aulas/Projecto/";
?> 

 

If someone can help me i'd be very gratefull, thanks  :)

Link to comment
Share on other sites

 

The error is simply saying that on line 65 of the index, you have called the "mysql_num_rows" function, the variable you gave it was not a resource but a boolean... ie true or false... In others words the mysql_num_rows is failing because the query failed.. the variable holding the query is false because the query most likely has some error in it. Maybe a filed name is wrong or something.

 

Whilst testing, one good way to check if your query is correct is:

if(!$someQuery)
  {
       echo mysql_error();
       exit();
   }

 

Link to comment
Share on other sites

hmm it's very strange, i added that condition you said after the query, the error is gone and i get this message on the page:

 

"No database selected"

 

How come that happens when i include the other file there with the connection and selection of the database? :/

 

...and i rechecked and there's no wrong filled names or so in the query ...i think

Link to comment
Share on other sites

Hey i just fixed it, i'm sorry it was a very stupid error and had nothing to do with php code lol...  the thing is i had the password varchar to 20 chars... and since i encrypted the passwords to md5, it gets more than 20 chars... i changed the varchar(100) and it worked :P

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.