473,406 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Login Problem

31
Hi, i do some code in order to learn login function and i find the code from internet, but when i run the code this error is appear

>>Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\login2\login.php on line 12

I do not know what the problem is, can someone help me please?

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. include("config.php");
  3. session_start();
  4. if($_SERVER["REQUEST_METHOD"] == "POST")
  5. {
  6. // username and password sent from Form 
  7. $myusername=addslashes($_POST['username']); 
  8. $mypassword=addslashes($_POST['password']); 
  9.  
  10. $sql="SELECT id FROM admin WHERE username='$myusername' and passcode='$mypassword'";
  11. $result=mysql_query($sql);
  12. $row=mysql_fetch_array($result);
  13. $active=$row['active'];
  14. $count=mysql_num_rows($result);
  15.  
  16.  
  17. // If result matched $myusername and $mypassword, table row must be 1 row
  18. if($count==1)
  19. {
  20. session_register("myusername");
  21. $_SESSION['login_user']=$myusername;
  22.  
  23. header("location: welcome.php");
  24. }
  25. else 
  26. {
  27. $error="Your Login Name or Password is invalid";
  28. }
  29. }
  30. ?>
  31. <form action="" method="post">
  32. <label>UserName :</label>
  33. <input type="text" name="username"/><br />
  34. <label>Password :</label>
  35. <input type="password" name="password"/><br/>
  36. <input type="submit" value=" Submit "/><br />
  37. </form>
Nov 6 '12 #1
6 2517
Rabbit
12,516 Expert Mod 8TB
Are you sure your connection is set up correctly in config.php?
Nov 6 '12 #2
huda89
31
I think so, because i just copy it from internet, and i change it according to my connection. Below the code for config.php

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $mysql_hostname = "localhost";
  3. $mysql_user = "root";
  4. $mysql_password = "";
  5. $mysql_database = "trial";
  6. $bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) 
  7. or die("Opps some thing went wrong");
  8. mysql_select_db($mysql_database, $bd) or die("Opps some thing went wrong");
  9. ?>
Nov 6 '12 #3
Rabbit
12,516 Expert Mod 8TB
Are you sure the query returns something? You should check that mysql_query() is returning true before continuing with the rest of your code. You should also check row count before fetching from it in case there are no records.
Nov 6 '12 #4
huda89
31
ok, thank you :)
let me check.
Nov 9 '12 #5
Please try it this php code
if your connection file is correct after you will use it
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     include("connection.php");
  3.     $Ocon = new connection();
  4.     $Ocon->connect(); 
  5.     if(isset($_REQUEST['btnlogin']))
  6.     {
  7.         $username = $_REQUEST['username'];
  8.         $password = $_REQUEST['password'];
  9.         $ssQuery = " SELECT * FROM admin WHERE username = '".$username."' AND password = '".$password."' ";
  10.         $result = mysql_query($ssQuery); 
  11.         $amInfo = $Ocon->fetch_data($result);
  12.         if($username== $amInfo[0]['username'] AND $password==$amInfo[0]['password'])
  13.         {
  14.              $_SESSION['username']=$_POST['username'];
  15.              header('Location: home.php') ;
  16.             exit;
  17.         }
  18.         else
  19.         {
  20.             header( 'Location: index.php?msg=invalid username or password') ;
  21.  
  22.         }
  23.     }
  24.     ob_flush();
  25. ?>

//connection.php


Expand|Select|Wrap|Line Numbers
  1. $mysql_hostname = "localhost";
  2. $mysql_user = "root";
  3. $mysql_password = "";
  4. $mysql_database = "trial";
  5. $bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) 
  6. or die("Opps some thing went wrong");
  7. mysql_select_db($mysql_database, $bd) or die("Opps some thing went wrong");
Nov 9 '12 #6
huda89
31
Thank You sharmahemal :)
Nov 16 '12 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Mike Hutton | last post by:
Hi, I have tried to keep things simple. Not simple enough, obviously. I have a set of intranet ASP.NET pages which access a SQL back-end through the normal SQLConnection stuff. I want to use...
1
by: George | last post by:
Hi. I've deployed a web application on a desktop computer running W2K and IIS. I'm using the desktop as a server. When I try to access the site, either from my development computer or if I...
1
by: Shmuel Shulman | last post by:
Hi When the program tries to refer to a file on the server I get an error saying that the username/password is incorrect although I did log in to the server when I tried to get a file manually...
1
by: Brad | last post by:
I am having a strange login problem that I have been dealing with for a week and cannot find an answer to. I am about ready to uninstall everything and then reinstall it. I am using Visual...
3
by: Joe Fawcett | last post by:
Dear All We have an application where users login, their name/password details are stored in a table, and now we want to add a third party bulletin board that lives in its own virtual directory....
5
by: guy | last post by:
I am not a web developer so this is probably easy! in a web app i have a login page if a user logs in, does stuff, logs out - which takes them back to the login page - how do i stop a new user...
1
by: KavithaSing | last post by:
Hi everyone, In our website we have an option ‘official login’ for users to login and send information through the site. We face the following problem while loggin in. We use the following...
6
by: =?Utf-8?B?eW9kYWt0?= | last post by:
I'm having issues with logging into my application after moving it from the development server to the live IIS server. Things I've already done: 1) I made sure that I have applicationName set as...
4
by: rhodarose | last post by:
Good day! I have an index.php or login page, when i login successfully and when i accidentally press the back button the login page appear, then when i try to login again, I could login again which...
3
by: VLJones68 | last post by:
I have a website which contains the root directory, a MemberPages directory and a PublicPages directory. Default.aspx resides in the root directory and includes a javascript login. Upon clicking...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.