ログインフォームにて、ユーザー登録されてない人は、最初にユーザー登録をし、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
1<?php 2session_start(); 3ini_set("include_path","./includes"); 4include("dbinfo.inc"); 5 6$errorMessage = ""; 7$login_no = $_SESSION['login_no']; 8 9if(isset($_SESSION['cust_id'])) 10{ 11$errorMessage = "No registration."; 12}else{ 13 $date = date("Y-m-d H:i:s"); 14// login_timeからcust_idを取り出す 15 $mysqli = new mysqli($host, $user, $passwd, $dbname); 16 $sql = "SELECT * FROM login_time WHERE cust_id ='".$_SESSION['cust_id']."'"; 17 $result = $mysqli->query($sql); 18 if(!isset($login_no)) 19 { 20 $login_no = $login_no++; 21 $sql = "INSERT INTO login_time (login_no,cust_id,logtime) VALUES 22 ('".$login_no."', 23 '".$_SESSION['cust_id']."', 24 '$date')"; 25 26 } 27 //$result = mysqli_query($cxn,$sql) 28 $result = $mysqli->query($sql) 29 or die("Couldn't execute query in login++."); 30 // if (!$result) { 31 // print('Cant execute query.' . $mysqli->error); 32 $mysqli->close(); 33 exit(); 34 // } 35 } 36// Cut data base 37//$result->close(); 38?> 39 40<!DOCTYPE HTML> 41<html> 42<head> 43<title>Exercise5</title> 44</head> 45</head> 46<body> 47<h1>You are logged in.</h1> 48<ul> 49 <li>Hi, <?php echo $_SESSION['username']; ?>!!</li> 50 <li>You logged in number of times:<?php echo $login_no; ?></li> 51 <li>Logtime:<?php echo $date; ?></li> 52</ul> 53<a href="logout.php?logout">Logout</a> 54 55 56</body> 57</html> 58
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/05/30 14:33