MachineGamer Posted April 25, 2014 Share Posted April 25, 2014 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 ! Quote Link to comment https://forums.phpfreaks.com/topic/288002-problem-with-login-php-mysql-script/ Share on other sites More sharing options...
bsmither Posted April 25, 2014 Share Posted April 25, 2014 One error I found is: <?phpif (isset($login_error) ... Allow me to suggest keeping the script start delimiter separated from code: <?php if (isset($login_error) ... Quote Link to comment https://forums.phpfreaks.com/topic/288002-problem-with-login-php-mysql-script/#findComment-1477224 Share on other sites More sharing options...
MachineGamer Posted April 25, 2014 Author Share Posted April 25, 2014 Thanks a lot my friend for your reply ,but when i did that ,he given an error : Parse error: syntax error, unexpected '{' in C:\xampp\htdocs\University\login.php on line 75 Quote Link to comment https://forums.phpfreaks.com/topic/288002-problem-with-login-php-mysql-script/#findComment-1477225 Share on other sites More sharing options...
bsmither Posted April 25, 2014 Share Posted April 25, 2014 According to the code above, line 75 is the HTML tag <fieldset>. Quote Link to comment https://forums.phpfreaks.com/topic/288002-problem-with-login-php-mysql-script/#findComment-1477230 Share on other sites More sharing options...
MachineGamer Posted April 25, 2014 Author Share Posted April 25, 2014 ok good i fixed the problem ,but still having this error see attached image : Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\University\login.php on line 16 Quote Link to comment https://forums.phpfreaks.com/topic/288002-problem-with-login-php-mysql-script/#findComment-1477231 Share on other sites More sharing options...
bsmither Posted April 25, 2014 Share Posted April 25, 2014 (edited) 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 April 25, 2014 by bsmither Quote Link to comment https://forums.phpfreaks.com/topic/288002-problem-with-login-php-mysql-script/#findComment-1477232 Share on other sites More sharing options...
MachineGamer Posted April 25, 2014 Author Share Posted April 25, 2014 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 Quote Link to comment https://forums.phpfreaks.com/topic/288002-problem-with-login-php-mysql-script/#findComment-1477234 Share on other sites More sharing options...
MachineGamer Posted April 25, 2014 Author Share Posted April 25, 2014 it's mysql_fetch_assoc() misspelling , how can i show this error in this code ,it's does not apear in my website : <?php if (isset($login_error) && ($login_error != "")){echo "<p color='#ff0000' style='margin-right: 10px;'".$login_error."</p>"; }?> Quote Link to comment https://forums.phpfreaks.com/topic/288002-problem-with-login-php-mysql-script/#findComment-1477236 Share on other sites More sharing options...
bsmither Posted April 25, 2014 Share Posted April 25, 2014 This part of the code: "<p color='#ff0000' style='margin-right: 10px;'".$login_error."</p>" does not have the right-angle to close the <p> tag. Try: "<p color='#ff0000' style='margin-right: 10px;'>".$login_error."</p>" Quote Link to comment https://forums.phpfreaks.com/topic/288002-problem-with-login-php-mysql-script/#findComment-1477283 Share on other sites More sharing options...
MachineGamer Posted April 25, 2014 Author Share Posted April 25, 2014 Yes , you are right and about the color that it didn't work this is the correct code : <?php if (isset($login_error) && ($login_error != "")){ echo "<p style='margin-right: 10px;color: #ff0000'>".$login_error."</p>"; }?> Quote Link to comment https://forums.phpfreaks.com/topic/288002-problem-with-login-php-mysql-script/#findComment-1477292 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.