Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/212370-login-failed/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/212370-login-failed/#findComment-1106524
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/212370-login-failed/#findComment-1106531
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.