ログインフォームにて、ユーザー登録されてない人は、最初にユーザー登録をし、DB:login tableにユーザー情報が登録され、その際にcust_idが発行されます。そのレジスタされた時をログイン回数0回目とし、DB:login_time tableに、ログイン時間(logtime),何回目のログインか(login_no), カスタムID(cust_id:key)が記録されます。その後、同じカスタムIDがログインするごとにlogin_noをカウントしていき、毎度ログイン情報を登録していきたいと思っています。
現在は”Couldn't execute query in login++.”と表示されてしまいます。
なぜQueryエラーになってしまうのでしょうか。
よろしくお願いします。
login_time tableは以下の通りです。
login_no INT(5)
How many times the customer logged in. Primary key.
cust_ID INT(5)
This is the key to joining by Customer ID with login table. Primary key.
logtime TIMESTAMP
When customer input the data from login form, automatically register the time.(Not update)
php
<?php session_start(); ini_set("include_path","./includes"); include("dbinfo.inc"); $errorMessage = ""; $login_no = $_SESSION['login_no']; if(isset($_SESSION['cust_id'])) { $errorMessage = "No registration."; }else{ $date = date("Y-m-d H:i:s"); // login_timeからcust_idを取り出す $mysqli = new mysqli($host, $user, $passwd, $dbname); $sql = "SELECT * FROM login_time WHERE cust_id ='".$_SESSION['cust_id']."'"; $result = $mysqli->query($sql); if(!isset($login_no)) { $login_no = $login_no++; $sql = "INSERT INTO login_time (login_no,cust_id,logtime) VALUES ('".$login_no."', '".$_SESSION['cust_id']."', '$date')"; } //$result = mysqli_query($cxn,$sql) $result = $mysqli->query($sql) or die("Couldn't execute query in login++."); // if (!$result) { // print('Cant execute query.' . $mysqli->error); $mysqli->close(); exit(); // } } // Cut data base //$result->close(); ?> <!DOCTYPE HTML> <html> <head> <title>Exercise5</title> </head> </head> <body> <h1>You are logged in.</h1> <ul> <li>Hi, <?php echo $_SESSION['username']; ?>!!</li> <li>You logged in number of times:<?php echo $login_no; ?></li> <li>Logtime:<?php echo $date; ?></li> </ul> <a href="logout.php?logout">Logout</a> </body> </html>
まだ回答がついていません
会員登録して回答してみよう