Ok, so l am new to php ... sort of, now l have managed to throw this together:

<?php

$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("test_database", $con);

	if(isset($_POST['Login']))
	{
		if($_POST['username']!='' && $_POST['password']!='')
		{
			//Use the input username and password and check against 'users' table
			$query = mysql_query('SELECT ID, username, Active FROM persons WHERE username = "'.mysql_real_escape_string($_POST['username']).'" AND password = "'.mysql_real_escape_string(md5($_POST['password'])).'"');
			
			if(mysql_num_rows($query) == 1)
			{
				$row = mysql_fetch_assoc($query);
				if($row['Active'] == 1)
				{
					$_SESSION['user_id'] = $row['ID'];
					$_SESSION['logged_in'] = TRUE;
					header("Location: members.php");
				}
				else {
					$error = 'Your membership was not activated. Please open the email that we sent and click on the activation link';
				}
			}
			else {		
				$error = 'Login failed !';		
			}
		}
		else {
			$error = 'Please enter both your username and password to access your account';
		}
	}
?>

Here is my html:

<form action="login.php" method="get">
			Username: <input type="text" name="username" /> <br>
			Password: <input type="password" name="password" /> <br><br>
			<input type="submit" value="Login" />
			<input type="reset" value="Reset" /> <br>
		</form>

Now, this is not working, when l try it it displays a blank white page, anyone know what l have done wrong?

Recommended Answers

All 5 Replies

ob_start();
session_start();

fix above code at top of page
and replace

mysql_fetch_assoc($query);

with

mysql_fetch_array($query);

and in form

<form action="login.php" method="post">

replace method="get" with method="post " as like above.
try it .

mmm, this didn't work, still displays a white page, due to my script it should open the file members.php if it logged in successfully shouldn't it? before it was adding extra stuff into my url bar too, what you have done has gotten rid of that, so that is good l guess...

Added a picture of the wampserver screen db, click image for larger view...

Does your page members.php have some code that checks the session variable is set? If so can you post that code?

and also

<input type="submit"  name="Login"value="Login" />

fix it. you forgot to write name="Login" in submit botton.

and also

<input type="submit"  name="Login"value="Login" />

fix it. you forgot to write name="Login" in submit botton.

Yep, done this, forgot about that, this is my members.php file:

<?php

session_start();

?>

<html>
<body>
help...

AZnythiong wrong here? thanks for everyones help so far, yous have been great...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.