angelfish723 Posted September 2, 2010 Share Posted September 2, 2010 You'll have to forgive me, as I am very new to what I am trying to learn! But there is a starting point for everything... I'm using PHP and MySQL for a password protected website that will have multiple users... and I think I'm very close to getting it to work. The password will be the same for all users, which they will be given. The problem I'm having is that when I put in a username and password, I get redirected to the Login Failed page. I think it might have something to do with the section of my code below. My table is called "users," and in the SESSION part, I've put the first three parts of the table in there... the user, full_names, and guest_one. I'm not really sure if I did that part correctly either. Also, I thought I read somewhere that the .md5 part of this code was for passwords that are encrypted. Do I need this if everyone is going to have the same password. This site is not high-security or anything. One last thing... I've set up my table in MySQL, and I know that I've got that set up correctly... the only problem is, how do I get all of the user, password, name information into that table? Where does it pull that information from. I have a mysql.sql text document, does it come from there? //Create query $qry="SELECT * FROM users WHERE user='$user' AND pass='".md5($_POST['password'])."'"; $result=mysql_query($qry); //Check whether the query was successful or not if($result) { if(mysql_num_rows($result) == 1) { //Login Successful session_regenerate_id(); $member = mysql_fetch_assoc($result); $_SESSION['SESS_USER'] = $user['user']; $_SESSION['SESS_FULL_NAMES'] = $user['full_names']; $_SESSION['SESS_GUEST_ONE'] = $user['guest_one']; session_write_close(); header("location: member-index.php"); exit(); }else { //Login failed header("location: login-failed.php"); exit(); } }else { die("Query failed"); } Let me know if you need more information that this. I'm sorry if these sounds like really dumb questions, but like I said, I'm brand new to this! I appreciate any help. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/212370-login-failed/ Share on other sites More sharing options...
shlumph Posted September 2, 2010 Share Posted September 2, 2010 Print out your query: <?php $qry="SELECT * FROM users WHERE user='$user' AND pass='".md5($_POST['password'])."'"; echo $qry; exit; Copy/paste it into your MySQL. Does it fetch back the user? Quote Link to comment https://forums.phpfreaks.com/topic/212370-login-failed/#findComment-1106508 Share on other sites More sharing options...
angelfish723 Posted September 2, 2010 Author Share Posted September 2, 2010 You're probably going to think I'm an idiot, but what do you mean by that? Paste it into the mysql.sql document? Or into the actual database on my host site? Quote Link to comment https://forums.phpfreaks.com/topic/212370-login-failed/#findComment-1106510 Share on other sites More sharing options...
shlumph Posted September 2, 2010 Share Posted September 2, 2010 Where are you working on this? On your local machine or on a hosting account somewhere? Quote Link to comment https://forums.phpfreaks.com/topic/212370-login-failed/#findComment-1106519 Share on other sites More sharing options...
shlumph Posted September 2, 2010 Share Posted September 2, 2010 How did you run queries to set up your database? Quote Link to comment https://forums.phpfreaks.com/topic/212370-login-failed/#findComment-1106520 Share on other sites More sharing options...
angelfish723 Posted September 2, 2010 Author Share Posted September 2, 2010 I'll just tell you the process I took to get where I am... I found a login code online using PHP and MySQL that will work perfectly for what I need, I just had to change some of the values to get it to connect to my database. It came with multiple files (the login-exec.php that connects to my MySQL, the actual login-form.php that has the user and pass form, the login failed page, a mysql.sql text document which I saved over with information from my table etc.) Then I have a host for my site (I'm using 1and1.com) where I set up my database and table. I was able to learn how to connect to the database and table through a tutorial somewhere, so I know I'm connecting to it correctly. I have a list of names, passwords, formal names (i.e. Mr. and Mrs. Smith), first and last names, etc. (this website is for a wedding... it's purpose is so that the guests can sign in and rsvp and view info about the wedding) and this is where I think something is screwed up. How does the table in the database gather all of that information? Where do I put all of that information so that say the "user" row in the table pulls the username when someone enters it in? I'm sure I'm not using the correct lingo, but I hope I'm explaining it well enough. Let me know if you want any examples from my codes or text documents. Quote Link to comment https://forums.phpfreaks.com/topic/212370-login-failed/#findComment-1106524 Share on other sites More sharing options...
shlumph Posted September 2, 2010 Share Posted September 2, 2010 Through 1and1.com, there's probably a phpmyadmin section, or something similar, where you can run queries on your database. You have to track down what went wrong. It might just be a data integrity problem. Simply troubleshoot to determine what's going wrong. Also, while learning PHP, I'd suggest installing apache, mysql, and php on your local machine. This way you can test everything more easily. Once it's working as expected, you can upload everything to your host. Quote Link to comment https://forums.phpfreaks.com/topic/212370-login-failed/#findComment-1106531 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.