- This topic is empty.
-
AuthorPosts
-
January 8, 2013 at 8:08 pm #41858cristinalmanzaMember
Hello css-tricks community.
I am trying to work on a little area for a website where the administrator can login and update a php table that offers 3 services. I have the php table working and updating properly. However when I did the login page. My page will not redirect to the page that I select. I used the [phpeasy steps login tutorial] but I cannot figure out why it is not working. I can get get it to tell me if the user name and password is wrong and also I can successfully sign out. Is there another tutorial I could use, or could you suggest what is wrong with my code. I studying php and I am trying to learn what is wrong with it. Any help will be greatly appreciated!!!** Thank you in advance!**
This is for the login page
[codepen for login page…](http://codepen.io/cristinalmanza/full/JzmLc “Code Pen for login”)This is for the login action php:
// Connect to server and select databse.
mysql_connect(“$host”, “$username”, “$password”)or die(“cannot connect”);
mysql_select_db(“$db_name”)or die(“cannot select DB”);// Define $myusername and $mypassword
$myusername=$_POST;
$mypassword=$_POST;// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql=”SELECT * FROM $tbl_name WHERE username=’$myusername’ and password=’$mypassword'”;
$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(‘myusername’);
session_register(‘mypassword’);
header(‘Location: http://www.mywebsite.com/php/success_login.php’);
}
else {
echo “Wrong Username or Password”;
}
ob_end_flush();
?>(http://www.phpeasystep.com/phptu/6.html “http://www.phpeasystep.com/phptu/6.html”)
January 8, 2013 at 8:21 pm #120345hotpinkMemberSomething I noticed in your example code…
This comment has “login_success.php”
// Register $myusername, $mypassword and redirect to file “login_success.php”
But this line has “success_login.php”
header(‘Location: http://www.mywebsite.com/php/success_login.php’)
Could this be the issue?
January 8, 2013 at 8:28 pm #120346cristinalmanzaMemberThank you so much for your response hotpink! I will do that and look at it and see if it is the problem. Thank you for taking time to check the code for me =) I really appreciate it
January 8, 2013 at 8:30 pm #120347cristinalmanzaMemberI just checked and that is not it =(.
January 9, 2013 at 1:58 am #120364BonzaiParticipantI wouldn’t recommend using mysql_connect for your login. You would be much better off using PDO. Here’s a tutorial on how to use it:
[PDO tutorial](http://www.phpeveryday.com/articles/PHP-Data-Object/PDO-Tutorial-P842.html “PDO tutorial”)
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.