Hi, yes the problem has been solved with mysql_fetch_assoc. We've also made changes based on your other recommendations. I don't understand them all yet, but I'm working on it!
Also, I tried making
$match = "select user_id from $table where username = '".$_POST['username']."'
and password = '".$_POST['password']."';";
into
$match = "select user_id from $table where username = '$_POST['username']'
and password = '$_POST['password']'";
but for some reason it gives a syntax error, so I just left it for now.
Here's what it looks like now:
<?php
include("connect.php");
if(isset($_POST['username'], $_POST['password']))
$match = "select user_id from $table where username = '".$_POST['username']."'
and password = '".$_POST['password']."';";
$qry = mysql_query($match)
or die ("Could not match data because ".mysql_error());
$num_rows = mysql_num_rows($qry);
if ($num_rows == 0) {
echo "Sorry, there is no username ".$_POST['username']." with the specified password.
";
echo "Try again";
exit;
}
$remember = $_POST['remember'];
$result = mysql_fetch_assoc($qry);
$user_id = $result['user_id'];
if ($remember) {
setcookie("loggedin", "TRUE", time()+3600*24);
setcookie("mysite_username", "".$_POST['username']."", time()+3600*24);
setcookie("mysite_userid", $user_id, time()+3600*24);
header("Location: members.php");
}
else {
setcookie("loggedin", "TRUE");
setcookie("mysite_username", "".$_POST['username']."");
setcookie("mysite_userid", $user_id);
$site_username = $_COOKIE["mysite_username"];
$site_userid = $_COOKIE["mysite_userid"];
header("Location: members.php?user=$site_username");
}
?>