doubt

6 views
Skip to first unread message

Saagar Varma

unread,
Jun 6, 2010, 12:01:54 PM6/6/10
to Delta NITT
hi...i hav 2 doubts...
firstly,how do we know the userid and password of uniserver??
secondly,i am trying to create a page to which the browser goes after
the login button is clicked on...the prob is the browser shows me the
entire php cose of the page rather than showing me my output.....can
anybody plz help me asap...this is the code of the 2nd page....

<?php

$username=$_POST['username'];
$password=$_POST['password'];


//The following if condition will come into working if the user has
not entered a correct username

if($username&&$password)
{
$connect_db=mysql_connect("localhost","root","root") or
die("Sorry,Cannot connect to the server");
mysql_select_db("loginpage") or die("Sorry,Cannot find the required
database");//loginpage is the database i have made
}

else
die("You have not entered username or password!!");
?>

Saagar Varma

unread,
Jun 6, 2010, 12:04:33 PM6/6/10
to Delta NITT
i mean the entire php code....sorry!

Dinesh

unread,
Jun 6, 2010, 12:36:15 PM6/6/10
to Delta NITT
This problem will be mostly encountered when the HTML tags in the PHP
file is not closed properly.... In such cases the php tags <?php and ?
> wont be recognised and so script is treated as mere text in a normal
HTML file....
The script u have written above has flaw... the variables $username
and $password is not checked for any values... so even if user enters
a random username and password these variables will be declared and
database will be connected...

Saagar Varma

unread,
Jun 6, 2010, 12:46:36 PM6/6/10
to delta...@googlegroups.com
first up,thanks!
nope,i am positive there is no prob with the html tags!!

and regarding the values...the if condition is for checking exactly whether the user is der in the database or not....can u come on fb??

Mohnish prasanna

unread,
Jun 6, 2010, 12:55:12 PM6/6/10
to Delta NITT
what are you exactly trying to do using this code this is no login
code.......there is no output intended if any input is given in the
username or pass field .....try rechecking ur code ....

for your first doubt- type http://localhost/apanel/phpmyadmin ---
>click on priviliges ---> click on add new user and creat a user of ur
choice

On Jun 6, 9:01 pm, Saagar Varma <saagartheb...@gmail.com> wrote:

Shankarram A

unread,
Jun 6, 2010, 1:24:36 PM6/6/10
to delta...@googlegroups.com
Check if apache is running. Is the first page a php page executing properly? Is it just this page or any other which dont execute the script? Whats the extension of the script?

Those are the simple reasons which you may want to check first.

Abhishek Shrivastava

unread,
Jun 6, 2010, 3:16:38 PM6/6/10
to delta...@googlegroups.com
There's no username and password of "uniserver" as such by default. If you're talking of phpmyadmin, its "root" and no password by default.

Secondly, the information you provided looks ambiguos. Please send the entire code of the 2 pages ur talking abt i.e. the page having the login button and the page which is supposed to be opened.

Saagar Varma

unread,
Jun 6, 2010, 3:39:56 PM6/6/10
to delta...@googlegroups.com
thanks a lot abhishek....here is the code of the 2 pages.....please keep in mind that the code to the 2nd page still has to be improved...this is a test to c if it is connecting with the database.....i still hav to create a session for the user once he logs in and then when he wants to log out....the code of the first file(with the login button)-
first file code-index.php
<html>
<head>
<title>
NUS Login Page
</title>


<style type="text/css">
#loginform{
border:2px solid #600;
background-color: #FFC;
width: 280px;

#loginform form{
margin : 5px;
}

label{
display:block;
width:90px;
float:left;
clear: both;
}

label,input{
 margin-bottom: 4px;
}
</style>
</head>
<body>


<div id="loginform">
<form action="login.php" method="post">
Username<input type="text" name="username"><br>
Password<input type="password" name="password"><br><br>
<input type="submit" value="Login">
</form>
</div>
</body>
</html>

the code of the 2nd file(upto the stage of testing if it is able to connect to the database)-login.php
<?php

$username=$_POST['username'];
$password=$_POST['password'];


//The following if condition is done in case user does not enter either username or password

if($username&&$password)
{echo "HI";// to test if it reaches inside the if condition!!
$connect=mysql_connect("localhost","root","root") or die("Sorry,Cannot connect to the server");
mysql_select_db("loginpage") or die("Sorry,Cannot find the required database");
}

else
 die("You have not entered username or password!!");
?>

thanks again....i hav been stuck on this since the last 4 hrs....and its very frustrating.....plz help....

Regards
Saagar

Abhishek Shrivastava

unread,
Jun 6, 2010, 3:49:54 PM6/6/10
to delta...@googlegroups.com
The code looks OK to me. What's the problem ur getting exactly ? Did that echo "HI"; worked ?

Saagar Varma

unread,
Jun 6, 2010, 3:56:24 PM6/6/10
to delta...@googlegroups.com
one small but unusual development....when i type the adress in the browser as http://localhost/delta_project  (the folder in which both the files are stored),it directly jumps to the first login page file and from there when i type the conditions,it works perfectly,ie,it connects to the database,shows hi and if i type anything wrong then it flashes the other message....

.the problem is that when i go to www folder in the w: created specifically by uniserver and try to run the first file from there...it goes to the 2nd file but it displays the full code of the 2nd file rather than showing...

this is very odd.....

thanks again...appreciate u takin ur valuable time for me...
Saagar

Saagar Varma

unread,
Jun 6, 2010, 4:44:22 PM6/6/10
to delta...@googlegroups.com
Abhishek One small query...is it ok if i submit the task by tomorrow night??it will be 7th june only rite?

thanks and good nite

Saagar

Abhishek Shrivastava

unread,
Jun 6, 2010, 7:08:44 PM6/6/10
to delta...@googlegroups.com
yes its fine .
--
Abhishek Shrivastava
E.C.E., N.I.T. Trichy

Dinesh

unread,
Jun 6, 2010, 11:55:09 PM6/6/10
to Delta NITT
I think u misunderstood.... The if condition doesnot check whether
user in database as you telling...
U need to pass mysql queries to check if user is there in table...
This code merely checks if $_POST variable is passed wothout null
value...
Secondly, I tested the code u gave to abishek... It works perfectly in
my wamp server and performs the task wat I mentioned above... Must be
some server problemm...
Take a bakup of www folder and reinstall uniserver and check again....
On Jun 6, 9:46 pm, Saagar Varma <saagartheb...@gmail.com> wrote:
> first up,thanks!
> nope,i am positive there is no prob with the html tags!!
>
> and regarding the values...the if condition is for checking exactly whether
> the user is der in the database or not....can u come on fb??
>

Saagar Varma

unread,
Jun 7, 2010, 12:54:36 AM6/7/10
to delta...@googlegroups.com
thanks a lot dinesh...appreciate it...:-)....

and thanks abhishek....

regards
Saagar

Saagar Varma

unread,
Jun 7, 2010, 9:22:44 AM6/7/10
to Delta NITT
i seem to have a problem...it is that after registering the user and
creating an account for him in the database,when i try to login with
the created account....i am not able 2...it keeps flashing PASSWORD
INCORRECT......odd thing is it was working sometime ago.....so there
must be some minor error which i am not able to detect.....this is the
code if someone can please help asap......

if($numrows !=0)
{//code to login
while($pass=mysql_fetch_assoc($query));//the while loop is for
the case that username matches and password doesn't
{
$dbusername=$pass['username'];
$dbpassword=$pass['password'];
}
echo $dbpassword;
$password=md5($password);echo $password;//encrypting the password
I SUSPECT THAT THE PROBLEM IS IN THIS LINE--->if($username==
$dbusername && $password==$dbpassword)//to check if the database
username matches to that provided
{
echo "You're in<br><a href='account.php'>Visit my Account</a>";
$_SESSION['username']=$dbusername;

}

else
echo "Password is incorrect";

}
else
die("That user doesnt exist");

i wud be grateful if someone can help!!

Saagar

Chakradar Raju

unread,
Jun 7, 2010, 9:31:06 AM6/7/10
to delta...@googlegroups.com
you've echoed the dbpassword and password, they must have been same, are they same?

Saagar Varma

unread,
Jun 7, 2010, 9:40:18 AM6/7/10
to delta...@googlegroups.com
thats the problem..i am unable to echo the dbpassword....i dunno why...i am quite sure that the details r stored properly in the database after registration.......thanks a lot Chakradhar....appreciate the help....

Saagar Varma

unread,
Jun 7, 2010, 9:40:47 AM6/7/10
to delta...@googlegroups.com
in the sense...it doesnt display anything for echo $dbpassword;   

Chakradar Raju

unread,
Jun 7, 2010, 9:42:24 AM6/7/10
to delta...@googlegroups.com
its better to declare the $dbpassword and $dbusername before the while loop.

Saagar Varma

unread,
Jun 7, 2010, 9:48:11 AM6/7/10
to delta...@googlegroups.com
how do i declare them before??i am equatting them to an arrray $pass which is fetching the values from the database....so if i hav to declare them earlier...wat do i declare them as?

Balanivash

unread,
Jun 7, 2010, 9:49:14 AM6/7/10
to Delta NITT
Hey,i think it'd be better if you form a query based on the username
and if the number of rows in the result is 0, then user doesn't exist,
and if the username matches, you could just check if the password
matches....This would be much easier.....

Saagar Varma

unread,
Jun 7, 2010, 9:55:10 AM6/7/10
to delta...@googlegroups.com
in that case...i would be removing username out of the picture isnt it...that i can do...but then again to check if the password matches or not i'd hav to create an if condition and then to fetch the password fr the database,i.e,$dbpassword.....so it doesnt make a difference does it?

thanks for the help..
Saagar

Chakradar Raju

unread,
Jun 7, 2010, 10:01:54 AM6/7/10
to delta...@googlegroups.com
just use the $dbusername and $dbpassword once before the while loop:
$dbusername = "";
$dbpassword = "";

Mohnish prasanna

unread,
Jun 7, 2010, 10:09:52 AM6/7/10
to Delta NITT
there might be 2 possiblities of problem :

1. the password in the database might not be encrypted.
2. try $dbusername = "$pass['username']"; and for the pass also........
(i am not so sure about the second but just give it a try)

On Jun 7, 7:01 pm, Chakradar Raju <chakradarr...@gmail.com> wrote:
> just use the $dbusername and $dbpassword once before the while loop:
> $dbusername = "";
> $dbpassword = "";
>
> On Mon, Jun 7, 2010 at 7:25 PM, Saagar Varma <saagartheb...@gmail.com>wrote:
>
>
>
> > in that case...i would be removing username out of the picture isnt
> > it...that i can do...but then again to check if the password matches or not
> > i'd hav to create an if condition and then to fetch the password fr the
> > database,i.e,$dbpassword.....so it doesnt make a difference does it?
>
> > thanks for the help..
> > Saagar
>

Saagar Varma

unread,
Jun 7, 2010, 10:10:50 AM6/7/10
to delta...@googlegroups.com
done but not working.....echo $password gives the same password stored in the database...which means i can c they r same but still not able to log in it flashes the message incorrect password!........and no output comes when i echo dbpassword or dbusername...cud there be a problem in fetching it fr the database??


Saagar

Saagar Varma

unread,
Jun 7, 2010, 10:13:45 AM6/7/10
to delta...@googlegroups.com
hey,

the password in the database is encrypted...i can c the encrypted form...and ur second pt does not work...

thanks again

Saagar

Chakradar Raju

unread,
Jun 7, 2010, 10:15:01 AM6/7/10
to delta...@googlegroups.com
did echo $dbpassword, printed what you expected?

Saagar Varma

unread,
Jun 7, 2010, 10:16:51 AM6/7/10
to delta...@googlegroups.com
m not able to print $dbpassword...it does not display anythin for that......i hav been trying 2 ways to print it-
1. echo $dbpassword;
2. echo $pass['password'];

none work....

Saagar

Mohnish prasanna

unread,
Jun 7, 2010, 10:23:18 AM6/7/10
to Delta NITT
try using

$password = md5($password);
$sql="SELECT * FROM $tbl_name WHERE username='$username' and
password='$password'";
$result=mysql_query($sql);

$count=mysql_num_rows($result);
$myrow = mysql_fetch_array($result);

if($count==1){
//conditions
}

On Jun 7, 7:10 pm, Saagar Varma <saagartheb...@gmail.com> wrote:
> done but not working.....echo $password gives the same password stored in
> the database...which means i can c they r same but still not able to log in
> it flashes the message incorrect password!........and no output comes when i
> echo dbpassword or dbusername...cud there be a problem in fetching it fr the
> database??
>
> Saagar
>
> On Mon, Jun 7, 2010 at 6:01 PM, Chakradar Raju <chakradarr...@gmail.com>wrote:
>
>
>
> > just use the $dbusername and $dbpassword once before the while loop:
> > $dbusername = "";
> > $dbpassword = "";
>
> > On Mon, Jun 7, 2010 at 7:25 PM, Saagar Varma <saagartheb...@gmail.com>wrote:
>
> >> in that case...i would be removing username out of the picture isnt
> >> it...that i can do...but then again to check if the password matches or not
> >> i'd hav to create an if condition and then to fetch the password fr the
> >> database,i.e,$dbpassword.....so it doesnt make a difference does it?
>
> >> thanks for the help..
> >> Saagar
>

Balanivash

unread,
Jun 7, 2010, 10:42:02 AM6/7/10
to Delta NITT
I think the query you use to fetch data from the db might have some
error...try checking that.....or check if the query returns any result
at all.......

Abhishek Shrivastava

unread,
Jun 7, 2010, 1:23:35 PM6/7/10
to delta...@googlegroups.com
while($pass=mysql_fetch_assoc($query));

There's a semicolon in the end of the while loop.  The while loop ends in itself until $pass is none and nothing gets stored in $dbpassword. Take care from next time and be more alert while coding in PHP. Its quite hard to debug them.

Saagar Varma

unread,
Jun 7, 2010, 3:23:15 PM6/7/10
to delta...@googlegroups.com
thanks abhishek....i rectified the problem.....

Saagar
Reply all
Reply to author
Forward
0 new messages