Jump to content

::::---- Problem with login php mysql script ----::::


MachineGamer

Recommended Posts

hey guys ,

i am new in php programing and i am having a lot of trouble trying to create a login php script to connect it with my mysql database (i've already create a database) 

i am getting error :

 

content of my database is :

Id_Enseignant Nom_Enseignant Prenom_Enseignant mail_enseignant Mot_de_passe 14 hh hhs   hhss                   

 

and this is my php script : 

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\University\login.php on line 16

+

line 16 is this line :

if(mysql_num_rows($sql) == 1){

plus it showing me this next to the submit button :"; }?>

-----------login.php----------------

<?php
require_once('init.php');
include_once("scripts/connect.php");
$login_error = "";
$email = "";
$password= "";


if(isset($_GET['login'])){




$email = strip_tags(mysql_real_escape_string($_POST['email']));
$password = strip_tags(mysql_real_escape_string($_POST['password']));


$sql = mysql_query("SELECT mail_enseignant,Nom_Enseignant,Mot_de_passe FROM enseignant WHERE email='".$email."' AND password='".$password."' LIMIT 1");


if(mysql_num_rows($sql) == 1){
$row = mysql_fetch_asooc($sql);
$_SESSION['mail_enseignant'] = $row['mail_enseignant'];
$_SESSION['Nom_Enseignant'] = $row['Nom_Enseignant'];
$_SESSION['Mot_de_passe'] = $row['Mot_de_passe'];


header("Location: index.php");
exit();
}else{
$login_error="invalid Information...";
}
}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="EN" lang="EN" dir="ltr">
<head profile="http://gmpg.org/xfn/11">
<title>Département Math-Info</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="imagetoolbar" content="no" />
<link rel="stylesheet" href="styles/layout.css" type="text/css" />
</head>
<body id="top">
<div class="wrapper row1">
  <div id="header" class="clear">
    <div class="fl_left">
      <h1><a href="index.php">Département Math-Info</a></h1>
      <p>Just Pour Vous</p>
    </div>
    <form action="#" method="post" id="login">
    <a href="login.php"><h4>Enseignant Login<h4></a>
</form>
  </div>
</div>
<!-- ####################################################################################################### -->
<div class="wrapper row2">
  <div id="topnav">
    <ul>
      <li><a href="index.php">Homepage</a></li>
      <li class="active"><a href="style-demo.php">Contact Us</a></li>
      <li><a href="nouveaute.php"> Nouveauté</a></li>
      
      <li><a href="note-off.php">NOTE TAB</a></li>
      <li class="last"><a href="gallery.php">Gallery</a></li>
    </ul>
    <div  class="clear"></div>
  </div>
</div>
<!-- ####################################################################################################### -->
<div class="wrapper row4">
  <div id="container" class="center">
    <!-- ####################################################################################################### -->
   <h3>Ensiegnant Login Below</h3>
   <form action="?login" method="post" >
      <fieldset>
        <legend>Enseingant Login</legend>


<p>Mail_Ens: <input type="text" name="email" value="<?php echo $email;?>" /></p>
        <p>Password: <input type="password" name="password" value="<?php echo $password;?>" /></p>
<p>
<?phpif (isset($login_error) && ($login_error != ""){
echo "<font color='#ff0000' style='margin-right: 10px;'".$login_error."</font>";
}?>
<input type="submit" value="Login Enseignant" name="submit_login"/></p>
      <!--  <input type="image" src="images/sign_in.gif" id="signin" alt="Sign In" />-->
      </fieldset>
    </form>
      
    <!-- ####################################################################################################### -->
    <div class="clear"></div>
  </div>
</div>
<!-- ####################################################################################################### -->
<div class="wrapper row5">
  <div id="footer" class="clear">
    <!-- ####################################################################################################### -->
    <div class="foot_contact">
      <h2>University Name Here</h2>
      <address>
      Address Line 1<br />
      Address Line 2<br />
      Town/City<br />
      Postcode/Zip
      </address>
      <ul>
        <li><strong>Tel:</strong> xxxxx xxxxxxxxxx</li>
        <li><strong>Fax:</strong> xxxxx xxxxxxxxxx</li>
        <li class="last"><strong>Email:</strong> <a href="#">contact@mydomain.com</a></li>
      </ul>
    </div>
    <div class="footbox">
      <h2>Administration</h2>
      <ul>
        <li><a href="#">Disclaimer</a></li>
        <li><a href="#">Accessibility</a></li>
        <li><a href="#">Freedom of Information</a></li>
        <li><a href="#">Website Privacy</a></li>
        <li><a href="#">Press Release Information</a></li>
        <li><a href="#">Annual Report</a></li>
        <li><a href="#">Financial Statements</a></li>
        <li><a href="#">Job Vacancies</a></li>
        <li class="last"><a href="#">Semester Dates</a></li>
      </ul>
    </div>
    <div class="footbox">
      <h2>Link Block 2</h2>
      <ul>
        <li><a href="#">Schools and Colleges</a></li>
        <li><a href="#">Student Activities</a></li>
        <li><a href="#">Student Affairs</a></li>
        <li><a href="#">Student Development</a></li>
        <li><a href="#">Student Financial Services</a></li>
        <li><a href="#">Student Group Directory</a></li>
        <li><a href="#">Student Life</a></li>
        <li><a href="#">International Students</a></li>
        <li class="last"><a href="#">Global Learning</a></li>
      </ul>
    </div>
    <div class="footbox last">
      <h2>Link Block 3</h2>
      <ul>
        <li><a href="#">Academic Advisory</a></li>
        <li><a href="#">Academic Assistance</a></li>
        <li><a href="#">Academic Calendars</a></li>
        <li><a href="#">Academics Office</a></li>
        <li><a href="#">Administration</a></li>
        <li><a href="#">Adult Learners</a></li>
        <li><a href="#">Alumni Chapters</a></li>
        <li><a href="#">Alumni Events</a></li>
        <li class="last"><a href="#">Residential Colleges</a></li>
      </ul>
    </div>
    <!-- ####################################################################################################### -->
  </div>
</div>
<!-- ####################################################################################################### -->
<div class="wrapper">
  <div id="copyright" class="clear">
    <p class="fl_left">Copyright © 2013 - All Rights Reserved - <a href="#">Domain Name</a></p>
    <p class="fl_right">Template by <a href="http://www.os-templates.com/" title="Free Website Templates">OS Templates</a></p>
  </div>
</div>
</body>
</html>

-----------connect.php----------------

<?php


$hostname = 'localhost';        // Your MySQL hostname. Usualy named as 'localhost', so you're NOT necessary to change this even this script has already online on the internet.
$dbname   = 'a_database';       // Your database name.
$username = 'root';             // Your database username.
$password = '';                 // Your database password. If your database has no password, leave it empty.


// Let's connect to host
mysql_connect($hostname, $username, $password) or DIE('Connection to host is failed, perhaps the service is down!');
// Select the database
mysql_select_db($dbname) or DIE('Database name is not available!');


?>

------------init.php--------------

<?php
session_start();
?>

check attached image to see how it's apper to me 

please ,any comment it will be very helpful for me thanks in advance !

 

post-168635-0-67944800-1398386164_thumb.jpg

Link to comment
Share on other sites

Please try this (the code you posted above must have had some edits, as line 16 is a blank line):

$sql = mysql_query("SELECT mail_enseignant,Nom_Enseignant,Mot_de_passe FROM enseignant WHERE email='".$email."' AND password='".$password."' LIMIT 1");
if (!is_resource($sql)) die("Query Failed. ".mysql_error($sql));

if(mysql_num_rows($sql) == 1){
Edited by bsmither
Link to comment
Share on other sites

Hey bsmither , i've add this code of line " echo mysql_error(); " in the script and it's says : that unknown email , so i changed it to  :

$sql = mysql_query("SELECT mail_enseignant,Nom_Enseignant,Mot_de_passe FROM enseignant WHERE mail_enseignant='".$email."' AND Mot_de_passe ='".$password."' LIMIT 1");

and password too , now i am getting : this error :

Fatal error: Call to undefined function mysql_fetch_asooc() in C:\xampp\htdocs\University\login.php on line 17

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.