Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 132,615 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 967 people online right now. Registration is fast and FREE... Join Now!




connecting the login screen with MySql database

 
Reply to this topicStart new topic

connecting the login screen with MySql database, i am not able to connect it to the db

msvp4u
post 15 Jul, 2008 - 05:31 AM
Post #1


New D.I.C Head

*
Joined: 15 Jul, 2008
Posts: 37


My Contributions


php

/*connect.php*/
<?
$db="test";
$host="localhost";
$loginname="loginname";
$password="md5[password]";
mysql_pconnect($host) or die(" Unable to connect to SQL server");
mysql_select_db($db) or die( "Unable to select database");
?>


php

/*login.php*/

<?php
ob_start();
session_start();
include "connect.php";
if(isset($_POST['Submit'])){
$loginname=$_POST['txtLoginName'];
$password=$_POST['txtPassWord'];
$query="select * from userlogin where loginname='$loginname' and password=md5('$password') ";
$result=mysql_query($query);
$num=mysql_num_rows($result);
if(flag<1 ){
$act = "Login failed! Either your password or username did not match";
}else{
$row = mysql_fetch_assoc($result);
$_SESSION['loginname'] = $loginname;
header("location:menu.php");
exit;
}
}
?>


table name :userlogin
fields : loginname char(50) not null,
password varchar(8) binary not null

Mod Edit: Please use code tags when posting your code. Code tags are used like so => code.gif

Thanks,
PsychoCoder smile.gif
User is offlineProfile CardPM

Go to the top of the page

MitkOK
post 15 Jul, 2008 - 05:38 AM
Post #2


D.I.C Regular

Group Icon
Joined: 9 Aug, 2007
Posts: 314



Thanked 12 times

Dream Kudos: 250
My Contributions


What errors do you get ?

And what is $password="md5[password]"; ?
User is offlineProfile CardPM

Go to the top of the page

msvp4u
post 15 Jul, 2008 - 06:22 AM
Post #3


New D.I.C Head

*
Joined: 15 Jul, 2008
Posts: 37


My Contributions


if i press anything in the text box is pressed both in loginname and in the password textbox it automatically goes to the next page after pressing the submit button.
md5 is used for encrypting the password entered




QUOTE(msvp4u @ 15 Jul, 2008 - 06:31 AM) *

/*connect.php*/
<?
$db="test";
$host="localhost";
$loginname="loginname";
$password="md5[password]";
mysql_pconnect($host) or die(" Unable to connect to SQL server");
mysql_select_db($db) or die( "Unable to select database");
?>


/*login.php*/

<?php
ob_start();
session_start();
include "connect.php";
if(isset($_POST['Submit'])){
$loginname=$_POST['txtLoginName'];
$password=$_POST['txtPassWord'];
$query="select * from userlogin where loginname='$loginname' and password=md5('$password') ";
$result=mysql_query($query);
$num=mysql_num_rows($result);
if(flag<1 ){
$act = "Login failed! Either your password or username did not match";
}else{
$row = mysql_fetch_assoc($result);
$_SESSION['loginname'] = $loginname;
header("location:menu.php");
exit;
}
}
?>


table name :userlogin
fields : loginname char(50) not null,
password varchar(8) binary not null

User is offlineProfile CardPM

Go to the top of the page

akozlik
post 15 Jul, 2008 - 06:31 AM
Post #4


D.I.C Addict

Group Icon
Joined: 25 Feb, 2008
Posts: 596



Thanked 22 times

Dream Kudos: 750
My Contributions


Is there any particular reason you are creating a persistent connection with mysql_pconnect()? You're including your connect file everytime the page is loaded, so try using mysql_connect(). I may be wrong though.

Also, why are you using $password = md5[password]? I'm sure you realize this but make sure your code actually says

php

$password = md5($password);


Will the script connect if you just go to //localhost/connect.php?

Finally, which die error are you receiving when you run the connection. Also, in your die() functions, add mysql_error() and let us know what error pops up. That's what's really going to help nail down what you're looking for

php

mysql_connect($host, $username, $password) or die ( "Unable to connect: " . mysql_error() );


Make sure you add your code between code tags when posting to the forum.

Oh, one more note. Make sure you sanitize your data! Don't put your $_POST variables directly into your SQL statements.

Let us know what errors you are receiving.

This post has been edited by akozlik: 15 Jul, 2008 - 06:32 AM
User is offlineProfile CardPM

Go to the top of the page

msvp4u
post 15 Jul, 2008 - 08:55 AM
Post #5


New D.I.C Head

*
Joined: 15 Jul, 2008
Posts: 37


My Contributions


thank you for your kind detailed explaination of the error committed by me .I wiil rectify all the mistakes pointed out by you and keep you posted.
User is offlineProfile CardPM

Go to the top of the page

akozlik
post 15 Jul, 2008 - 08:56 AM
Post #6


D.I.C Addict

Group Icon
Joined: 25 Feb, 2008
Posts: 596



Thanked 22 times

Dream Kudos: 750
My Contributions


Sounds good. Make sure you post all the errors that you're receiving. That'll really help us figure out what's going on.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 02:54AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month