Forum Moderators: coopster
case "login":
$cxn = mysqli_connect($host, $user, $passwd,$dbname)
or die ( "Couldn't connect to server. ") ;
$sql = "SELECT loginName FROM member
WHERE loginName='$_POST[fusername] ' " ;
$result = mysqli_query($cxn, $sql)
or die ("Couldn't execute query.") ;
$num = mysqli_num_rows($result);
if ($num > 0) // login name was found
{
$sql = "SELECT loginName FROM member
WHERE loginName='$_POST[fusername] '
AND password=md5('$_POST[fpassword]') " ;
$result2 = mysqli_query($cxn,$sql)
or die("Couldn't execute query 2.");
$num2 = mysqli_num_rows($result2);
if ($num2 > 0) // password is correct
{
$_SESSION['auth']="yes";
$logname=$_POST['fusername'];
$_SESSION['logname'] = $logname;
$today = date("Y-m-d h:i:s");
$sql = "INSERT INTO login (loginName,loginTime)
VALUES ('$logname','$today')";
$result = mysqli_query($cxn,$sql)
(35) or die("Can't execute insert query.");
header("Location: member_page.php");
}
else // password is not correct
{
$message="The Login Name, '$_POST[fusername]'
exists, but you have not entered the
correct password! Please try again.<br />";
include("login_form.inc");
}
}
elseif ($num == 0) // login name not found
{
$message = "The Login Name you entered does not
exist! Please try again.<br />";
include("login_form.inc");
}
break;
have you tried echoing the query to see if it looks correct?
also it is great to put or die on your query exec but what you really need and want is this
$result = mysqli_query($cxn,$sql) or die("Can't execute insert query: " . mysqli_error());
this will return the actual error from mysql and give you some useful data
or die("Can't execute insert query: " . mysqli_error());
Warning: mysqli_error() expects exactly 1 parameter, 0 given in /home/music/public_html/login.php on line 39
Can't execute insert query:
[edited by: dangeh at 3:42 pm (utc) on Sep. 14, 2007]
meaning use echo [php.net]
like so
$sql = "INSERT INTO login (loginName,loginTime) VALUES ('$logname','$today')";
echo '<p>the query looks like this: ',$sql;
I'm liking the "improved" mysql functions less and less
so you need to pass it the link/connection, as mentioned on the manual page
[php.net...]
$result = mysqli_query($cxn,$sql) or die("Can't execute insert query: " . mysqli_error($cxn));
the manual is your best friend