It is currently Thu Nov 22, 2018 10:25 am


All times are UTC


Forum rules


Please click here to view the forum rules



Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: PHP login script
PostPosted: Sun May 31, 2009 6:28 pm 
Noobie
Noobie

Joined: Sun May 31, 2009 6:06 pm
Posts: 1
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 :(. 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>&nbsp;</td>
<td>&nbsp;</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;


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 03, 2010 8:45 pm 
Noobie
Noobie

Joined: Sun Oct 19, 2008 8:53 am
Posts: 3
Code:
<?php
ob_start();
$link = mysql_connect('mysql2.100ws.com', 'username', 'password');
if (!$link) {
die('Could not connect: ' . mysql_error());
exit;
}


$myusername = addslashes(trim($_POST['myusername']));
$mypassword = addslashes(trim($_POST['mypassword']));

$result=mysql_query('SELECT * FROM members WHERE username="'.$myusername.'" AND password="'.$mypassword.'"') or die(mysql_error());

$count = mysql_num_rows($result);

if($count == 1)
{

session_register("myusername");
session_register("mypassword");
header("location:login_success.php");
}

else
{
echo "Wrong Username or Password";
}

ob_end_flush();
?>


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ]  Moderators: fhmagic, KJ, Moderators, Support Team

All times are UTC


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
100WebSpace © 2011