Hi again,
Have a look at this 'tidied up' script and see if it makes sense. There were several 'issues' in your script and it's probably easier to show you this than try to explain everything.
If you don't understand anything, come back. Also, it might not do exactly what you want, but from your original it's hard to tell what your exact goal actually is.
Anyway ...
<?php
session_start();
// Test everything ...
if(!isset($_POST['email']) || !isset($_POST['password1']){
echo 'Must provide both email and password.<br>Please try <a href="customerlogin.php>logging in again</a>';
exit;
}
// PUT IN YOUR CORRECT DETAILS HERE
$link = mysql_connect("localhost", "XXX", "XXX")
or die("Couldn't connect to MySQL");
$db = "test";
mysql_select_db($db)
or die("Couldn't open ".$db.": ".mysql_error());
$query = "
SELECT *
FROM members
WHERE email='".$_POST['email']."'
AND password1='".$_POST['password1']."'
";
$result = mysql_query($query) or die('error making query');
// Check for exactly 1 result
if(mysql_num_rows($result) != 1){
echo 'Sorry Details not valid.<br>Please try <a href="customerlogin.php>logging in again</a>';
exit;
}
// If we've made it here, all's well
$_SESSION['email'] = $_POST['email'];
// Get data ... don't use mysql_result()
// ASSUMING customer_id, first_name and second_name are db fields
$row = mysql_fetch_array($result);
$_SESSION['customer_id'] = $row['customer_id'];
$_SESSION['first_name'] = $row['first_name'];
$_SESSION['second_name'] = $row['second_name'];
?>
<html>
<body>
<?
echo $_SESSION['first_name'].' '.$_SESSION['second_name'];
?>
</body>
</html>
Remember ... I can't easily debug typo's.
Hope that helps.
Paul 🙂