100 Web Space http://forum.100webspace.com/ |
|
PHP login script http://forum.100webspace.com/viewtopic.php?f=5&t=43697 |
Page 1 of 1 |
Author: | donbre [ Sun May 31, 2009 6:28 pm ] |
Post subject: | PHP login script |
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 ![]() 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; |
Author: | georgi bancov [ Sat Apr 03, 2010 8:45 pm ] |
Post subject: | |
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(); ?> |
Page 1 of 1 | All times are UTC |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |