Hey everyone

I've made this website and want to use PHP to allow users to register and login. I've created a database and connected to it, i've also created the table to store data from the registration page.

I've tested it and PHP for the registration page seems to be working, when a enter my data and click submit and page is then returned saying "1 record added". The problem i'm having is with the login page. I enter the same details used to register and click submit. Instead of logining me in it takes ages to loads and then IE just says "page cannot be found"

Can anyone please help me figure out why it isn't working?

All help is greatly appreciated

Heres my coding

insert.php (registration page)

<?php 
$con = mysql_connect("localhost","u08103765","aliasurn"); 
if (!$con) 
{ 
die('Could not connect: ' . mysql_error()); 
} 
mysql_select_db("u08103765", $con); 
$sql="INSERT INTO member (firstname, surname, email, password, address1, address2, address3, postcode, telephonenumber, mobilenumber) 
VALUES 
('$_POST[firstname]','$_POST[surname]','$_POST[email]','$_POST[password]','$_POST[address1]','$_POST[address2]','$_POST[address3]','$_POST[postcode]','$_POST[telephonenumber]','$_POST[mobilenumber]')"; 
if (!mysql_query($sql,$con)) //we call the function 
{ // inside IF statement 
die('Error: ' . mysql_error()); // to check and 
} 
else 
{ 
echo ("1 record added"); // get some feedback 
} 
mysql_close($con) 
?>

that works fine and saves the data correctly in the table

login.php - this is the code i use to try and login but everytime i try it fails..

<?php $host="localhost"; // Host name    
   
$dbusername="u08103765"; // Mysql username    
   
$dbpassword="aliasurn"; // Mysql password    
   
$db_name="u08103765"; // Database name    
   
$tbl="member"; // Table name    
   
// This connects to server and then selects the members databse.    
   
mysql_connect("$host", "$dbusername", "$dbpassword")or die("cannot connect");    
   
mysql_select_db("$db_name")or die("cannot select DB");    
   
// Assign the username and password from the form to variables.    
   
$username=$_POST['email'];    
   
$password=$_POST['password'];    
   
$sql="SELECT * FROM $tbl WHERE username='$email' and password='$password'";    
   
$result=mysql_query($sql);    
   
// This counts to see how many rows were found, there should be no more than 1    
   
$count=mysql_num_rows($result);    
   
// If result matched $email and $pass, table row must be 1    
   
if($count==1){    
   
// Register $email, and redirect to file "login_success.php"    
session_start();    
$_SESSION["logged"] = 1;    
header("location:index.php");    
}    
else {    
$_SESSION["logged"] = 0;    
header("location:login.php");    
   
}    
   
?>

login_success.php - this is the page i want the logged in member to be redirected to

// Check to see if session is not registered, if it is not redirect the user back to the notloggedin.php file.    
   
// Put this code in first line of every web page that you only want logged-in users to see.    
   
<?php session_start();    
if($_SESSION['logged'] != 1){ header("location:login.php"); }    
   
?>   

<html> 

<head> 

<meta http-equiv="REFRESH" content="5;url=http:"...members.html"> 

</head> 
</html>

I know ...members.html isnt a proper link but i still need to create the page so i can fill that in later

Hope you can help me

Recommended Answers

All 3 Replies

did you echo the count and see if it is getting a value ?

first off i would not show your username and pasword for your
db security issue

did you echo the count and see if it is getting a value ?

How do i do that? (sorry im not very good with php! i followed a tutorial for most of this)

Cheers

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.