snsz Posted April 15, 2012 Share Posted April 15, 2012 when i log in here i get this error: 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 Quote Link to comment https://forums.phpfreaks.com/topic/260955-need-some-little-help-here/ Share on other sites More sharing options...
freelance84 Posted April 15, 2012 Share Posted April 15, 2012 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(); } Quote Link to comment https://forums.phpfreaks.com/topic/260955-need-some-little-help-here/#findComment-1337431 Share on other sites More sharing options...
snsz Posted April 15, 2012 Author Share Posted April 15, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/260955-need-some-little-help-here/#findComment-1337435 Share on other sites More sharing options...
creata.physics Posted April 15, 2012 Share Posted April 15, 2012 Can you run the query in phpmyadmin? If it returns results then double check your database connection because it wouldn't provide you with that message for no reason. Quote Link to comment https://forums.phpfreaks.com/topic/260955-need-some-little-help-here/#findComment-1337440 Share on other sites More sharing options...
snsz Posted April 15, 2012 Author Share Posted April 15, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/260955-need-some-little-help-here/#findComment-1337443 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.