Hello,
I am working the PHP & MySQL for Dummies book. A lot of the material has gone fine or I've figured out what the problem was. However, I'm trying to insert a row into the MySQL table Login each time the user logs in. The login itself goes fine, but no row is added to that table.
I recently updated my Dreamhost php version to 5.3.
The Login table has two fields: loginName loginTime
I receive no errors of any kind.
I am able to add a row to the table in phpMyAdmin using INSERT INTO with the user's name and NOW()
Line 33: I've tried some syntax things like adding periods at each end of $_SESSION or making it '$_SESSION['logname']' etc. I also tried substituting the post variable.
This is what I believe to be the applicable part of the file (line 30 and following I think):
session_start(); #8
switch (@$_POST['Button']) #9
{
case "Log in": #11
include("xxxxx"); #12
$cxn=mysqli_connect($host,$user,$password,$dbname)
or die("Query died: connect".mysqli_error ($cxn)); #14
$sql="SELECT loginName FROM Member
WHERE loginName='$_POST[fusername]'";
$result=mysqli_query($cxn,$sql)
or die("Query died: fusername: ".mysqli_error($cxn));
$num=mysqli_num_rows($result); #19
if($num > 0) //login name was found #20
{
$sql="SELECT loginName FROM Member
WHERE loginName='$_POST[fusername]'
AND password=('$_POST[fpassword]')";//took out md5 before (
$result2=mysqli_query($cxn,$sql)
or die("Query died: fpassword"); #26
$num2=mysqli_num_rows($result2); #27
if($num2 > 0) //password matches #28
{$_SESSION['auth']="yes"; #30
$_SESSION['logname']=$_POST['fusername']; #31
$sql="INSERT INTO Login (loginName,loginTime)
VALUES ('$_SESSION[logname]',NOW())"; #changed $_SESSION[logname] to $_POST[fusername]
$result=mysqli_query($cxn,$sql)
or die("Query died: insert"); #35
header("Location: SecretPage.php"); #36
}
else // password does not match #38
Thanks,
Matt