Hi, i am desperatly trying to create a registration/login system, and have tried countless tutorials, but i can never seem to get them working, and i am getting really fed up!
I have recently tried the a new tutorial, which is well explained, and i have integrated into my website design, changing code etc.
The registration side of my system works fine, updates to my database with no problems, its just the login that doesn't work.
i have a login_form.php page which holds my form where the user enters their username and password and submits, which calls the login.php script. But when it is called, i just get a white screen, no errors or anything. i did have an include at the top of this page instead of my connection script being directly on the page, because i wasnt comfortable that it was working correctly, still doesnt work either way.
i will attach a jpg file of my table contents, and include the code below, its easier to see the problem that way. can someone please have a look and see where i could be going wrong? my database is called "customerhouses_db" and my table is called "customer".
login_form.php
<?php include "TopContent.html"; ?>
<div id="mainContainer">
<div id="StripeBackground"></div>
<div id="Title"><h2 class="shadow">Log in here</h2></div>
<div id="loginText">Not registered? Please register here and start looking for your dream home now!<br />Otherwise please enter your username and password below to sign in to your profile</div>
<div id="submitCustomerForm">
<FORM ACTION="login.php" METHOD="POST" NAME="contact_form">
<TABLE width="580">
<TR>
<TD width="40"></TD>
<TD colspan="4" border="0"><span class="asterix">*</span> Indicates a required field</TD>
</TR>
<TR border="0">
<TD></TD>
<TD></TD>
<TD width="187" align="left">Your Username:<span class="asterix"> *</span></font></TD>
<TD width="27"></TD>
<TD width="240" align="right"> <input class="fade" name="username" type=text size="30" maxlength="12"></TD>
</TR>
<TR border="0">
<TD></TD>
<TD></TD>
<TD width="187" align="left">Your Password:<span class="asterix"> *</span></font></TD>
<TD width="27"></TD>
<TD width="240" align="right"> <input class="fade" name="password" type=text size="30" maxlength="12"></TD>
</TR>
<TR height="50" border="0">
<TD></TD>
<TD><label><input name="remember" type="checkbox" id="Consent1" /></label></TD>
<TD align="left">Remember me?</TD>
<TD></TD>
</TR>
<TR border="0">
<TD></TD>
<TD></TD>
<TD></TD>
<TD></TD>
<TD align="center"><input type="image" src="Images/loginButton.jpg" name="Submit" /></TD>
</TR>
</FORM>
<FORM ACTION="forgotten_pass.php" METHOD="POST" NAME="contact_form">
<TR border="0" colspan="5">
<TD colspan="5"><hr /></TD>
</TR>
<TR border="0">
<TD></TD>
<TD colspan="4"></TD>
</TR>
<TR border="0">
<TD></TD>
<TD colspan="4"><h3>Forgotten your password?</h3></TD>
</TR>
<TR border="0">
<TD></TD>
<TD colspan="4"><span class="textSmall">If you have forgotten your password, then don't worry! just provide us with your registered email address below and we will give you easy instructions on how to reset your password</span></TD>
</TR>
<TR height="20" border="0">
<TD></TD>
<TD colspan="4"></TD>
</TR>
<TR border="0">
<TD></TD>
<TD></TD>
<TD width="187" align="left">Email:</TD>
<TD width="27"></TD>
<TD width="240" align="right"> <input class="fade" name="email" type=text size="30" maxlength="12"></TD>
</TR>
<TR height="20" border="0">
<TD></TD>
<TD colspan="4"></TD>
</TR>
<TR border="0">
<TD></TD>
<TD></TD>
<TD></TD>
<TD></TD>
<TD align="center"><input type="image" src="Images/requestButton.jpg" name="Submit" /></TD>
</TR>
</TABLE>
</FORM>
</div>
<div id="footer">
<?php include "BottomContent.html"; ?>
</div>
</div>
login.php
]<?php
session_start();
header("Cache-control: private");
$user = $_POST['username'];
$pass = $_POST['password'];
echo $user;
echo $pass;
$con = mysql_connect("localhost","root","12waldron"); //Replace with your actual MySQL DB Username and Password
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("customerhouses_db", $con); //Replace with your MySQL DB Name //change to database connection file
// checking if the user exists
$sql_user_check = "SELECT * FROM customer WHERE username='$user'"; //your table name here
$result_name_check = mysql_query($sql_user_check);
$usersfound = mysql_num_rows($result_name_check);
// if user not found, note that and end
if ($usersfound < 1) {
$error = "User $user not found.";
// if user does exist, continue with processing
} else {
// checking if passwords match
$sql_pass_get = "SELECT * FROM customer WHERE username='$username'"; //your table name here
$user_info = mysql_fetch_array(mysql_query($sql_pass_get));
$encryptpass = $user_info['encryptpass'];
// if doesn't match, note that and end
if ($encryptpass != md5($password)) {
$error = "Invalid password. Try again.";
} else {
//create sessions for each table entry
$_SESSION['userid'] = $user_info['id'];
$_SESSION['username'] = $user_info['username'];
$_SESSION['title'] = $user_info['title'];
$_SESSION['forename'] = $user_info['forename'];
$_SESSION['surname'] = $user_info['surname'];
$_SESSION['email'] = $user_info['email'];
$_SESSION['encryptpass'] = $user_info['encryptpass'];
$_SESSION['membership'] = $user_info['membership'];
$_SESSION['paid'] = $user_info['paid'];
}
}
//checks username session is registered, if it isn't checks if a value is assigned to error, if it has been
//output error and send them back to login screen, otherwise they are logged in correctly and welcome them
if (!$_SESSION['username']) {
if ($error) {
echo $error;
include("login.html")
} else {
include("welcome.html")
}
//otehrwise they are still logged in and welcome them back!
} else {
echo "<html><head><title>Welcome Back</title></head><body>Welcome back ".$_SESSION['username']." <a href=\"settings.php\">Click here</a> to view your current settings.</body></html>";
}
?>
please can someone help, i am going out of my mind trying to figure this out, i have tried about 6-7 different ways, none of them seem to work for me! please help!!
cheers
Craig (barbs75)