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

Join 105,763 PHP Programmers for FREE! Ask your question and get quick answers from experts. There are 1,702 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



Error retriving data

 
Reply to this topicStart new topic

Error retriving data

msvp4u
post 15 Jul, 2008 - 10:02 AM
Post #1


New D.I.C Head

*
Joined: 15 Jul, 2008
Posts: 30


My Contributions


[quote]
the problem which is i face is that while entering the username and password in the form and click the submit button it shows Wrong Username or Password
CODE

<?php
$host="localhost"; // Host name
$username=""; // Mysql username
$userpassword=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="userlogin"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$userpassword")or die("Cannot connect to the Data Base");
mysql_select_db("$db_name")or die("Cannot select DB");

// username and password sent from form
$loginname=$_POST['txtLoginName'];
$password=$_POST['(txtPassWord)'];

// To protect MySQL injection
$loginname = stripslashes($loginname);
$password = stripslashes($password);
$loginname = mysql_real_escape_string($loginname);
$password = mysql_real_escape_string($password);

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

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("loginname");
session_register("password");
header("location:./login_success.php");
}
else {
//header("location:./main_login.php");
echo "Wrong Username or Password";
}
?>
User is offlineProfile CardPM

Go to the top of the page


PsychoCoder
post 15 Jul, 2008 - 10:05 AM
Post #2


DIC.Rules == true;

Group Icon
Joined: 26 Jul, 2007
Posts: 7,030



Thanked 47 times

Dream Kudos: 7600

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, GDI

My Contributions


The "Introduce Yourself" forum is for introductions only, please post your programming questions in the proper forum (in this case the PHP forum). Ill move this to the PHP forum for you


BTW: Welcome to Dream.In.Code, hope you enjoy your stay smile.gif
User is online!Profile CardPM

Go to the top of the page

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


New D.I.C Head

*
Joined: 15 Jul, 2008
Posts: 30


My Contributions



sorry i did not make a notice of that and thanks for your guidence.


QUOTE(PsychoCoder @ 15 Jul, 2008 - 10:05 AM) *

The "Introduce Yourself" forum is for introductions only, please post your programming questions in the proper forum (in this case the PHP forum). Ill move this to the PHP forum for you


BTW: Welcome to Dream.In.Code, hope you enjoy your stay smile.gif

User is offlineProfile CardPM

Go to the top of the page

JBrace1990
post 15 Jul, 2008 - 10:47 AM
Post #4


D.I.C Regular

Group Icon
Joined: 9 Mar, 2008
Posts: 293



Thanked 10 times

Dream Kudos: 350
My Contributions


where you have $result=mysql_query($sql);. add an or die(mysql_error()); to the end of it so it becomes $result=mysql_query($sql)or die(mysql_error());
User is online!Profile CardPM

Go to the top of the page

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


New D.I.C Head

*
Joined: 15 Jul, 2008
Posts: 30


My Contributions


QUOTE

i have changed it like as you said $result=mysql_query($sql)or die(mysql_error());
i have made an error in the query and rectified it as this $sql="SELECT * FROM $tbl_name WHERE loginname ='$loginname' and password='$password'"; but still the error is persistent

User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 8/21/08 01:43PM

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