I am fairly new to PHP/MYSQL, but even looking up help in forums, question boards, FAQs, and even tutorials, I cannot for the life of me figure out what's wrong with my scripts. It connects to my database, but every single time it tells me I have wrong username/pw. I know 100% sure that the login I am putting in is the correct info saved in the database, therefore it's a coding error
![Sad :(](./images/smilies/icon_sad.gif)
. also while toying with the check login script attempting different ways to make it work, i made it accept any login as correct, and I got could not find login_success.php, which I also tested multiple ways of doing this to determine I have some error in my code. I may have fixed this, a I cannot repeat the error now, but just wanted to mention it so that part could be scrutinized as well. Thanks in advance for any help.
My current set up is:
main_login.php
Code:
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post" action="checklogin.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><strong>Member Login </strong></td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="myusername" type="text" id="myusername"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="mypassword" type="text" id="mypassword"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
checklogin.php comes next:
Code:
<?php
ob_start();
$link = mysql_connect('mysql2.100ws.com', 'username', 'password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM members WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count==1){
"login_success.php"
session_register("myusername");
session_register("mypassword");
echo "Welcome $myusername";
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
ob_end_flush();
?>
and finally login_success.php
Code:
<?
session_start();
if(!session_is_registered(myusername)){
header("location:main_login.php");
}
?>
<html>
<body>
Login Successful
</body>
</html>
Edit: ooops, forgot to include the table:
Code:
CREATE TABLE `members` (
`id` int(4) NOT NULL auto_increment,
`username` varchar(65) NOT NULL default '',
`password` varchar(65) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM;