FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


[URGENT]Simple authentification does not work!!!





pollux1er
I have written a script of autentification which does not work, although i find it as simple as possible.

this is it:

connexion.php

Code:

<?php
include_once "bd.php";

$login = $_POST['login'];
$pass = $_POST['pass'];

$pass = md5($pass);

$connexion = new BD();

$connexion->Connexion();

$requete = "SELECT * FROM connexion WHERE login='$login' AND pass='$pass';";
$result = mysql_query($requete);

$con = mysql_num_rows($result);

if ($con!=0) {
header ("Location:login.php");
}

else { header ("Location:../"); }
?>


bd.php

Code:

<?php

class BD {

   var $Serveur;
   var $Utilisateur;
   var $MotDePasse;
   var $BaseDeDonnees;
   var $connexion;
   
   function BD() {
   $this->Serveur = "localhost";
   $this->Utilisateur = "patient";
   $this->MotDePasse = "012546";
   $this->BaseDeDonnees = "pph";
   }
   function Connexion() {
   $this->connexion = mysql_connect("$this->Serveur", "$this->Utilisateur", "$this->MotDePasse") or die ("Impossible de se connecter");
   $this->SelectionneBD();
   }
   function Deconnexion() {
   $deconnexion = mysql_close($this->connexion);
   }

   function SelectionneBD () {
   $selection = mysql_select_db($this->BaseDeDonnees);
   }}   
?>


The mistake on the screen is :

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/hotelpen/public_html/administration/connexion.php on line 16

Warning: Cannot modify header information - headers already sent by (output started at /home/hotelpen/public_html/administration/connexion.php:16) in /home/hotelpen/public_html/administration/connexion.php on line 22

The line 16 is : $con = mysql_num_rows($result);
the line 22 : else { header ("Location:../"); }

Please help me to understant why it is not working.
Star Wars Fanatic
The second error is because of the first one, lol. It outputs the first error, and the header can't be outputted because the error already was. So it throws another error. So fix the first one and both will be fixed.

As for the first one, put this line right after line 16:

Code:
echo mysql_error ( ) ;


It will tell you what's wrong with the mysql query and why it's not returning anything.
Put that line in, run the code, and tell us the output.
pollux1er
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/hotelpen/public_html/administration/connexion.php on line 16
No database selected
Warning: Cannot modify header information - headers already sent by (output started at /home/hotelpen/public_html/administration/connexion.php:16) in /home/hotelpen/public_html/administration/connexion.php on line 22


This is the new error.
I think it is now easy for me to know more... Wink
pollux1er
There was a mistake on the name of the database, but it does not still work.
Star Wars Fanatic
How does it not work?
pollux1er
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/hotelpen/public_html/administration/connexion.php on line 16
No database selected
Warning: Cannot modify header information - headers already sent by (output started at /home/hotelpen/public_html/administration/connexion.php:16) in /home/hotelpen/public_html/administration/connexion.php on line 22

This is the message i still receive after modifying the name of the database, that i thought was the problem coming from.
pollux1er
I saw the problem. The Database was not selected because the user i was using to connect to the database does not have any privileges on the database. Thanks...
Related topics
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.