2016-02-26 51 views
0

您好我試圖將用戶名,他們鍵入到logattempt表 但它不承認我已經宣佈

<?php 
$servername = "localhost"; 
$user = "root"; 
$dbpassword=""; 
$dbname = "hrms"; 
$username=$_POST['username']; 
$password=$_POST['password']; 
$conn = new mysqli($servername, $user, $dbpassword, $dbname); 
if ($conn->connect_error) { 
    die("Connection failed: " . $conn->connect_error); 
} 

$sql = "SELECT * FROM users WHERE username='$username' AND password='$password'"; 
$result = $conn->query($sql); 

if ($result->num_rows > 0) { 

header("location: main.php"); 
} else { 
$sql = "INSERT INTO logattempt (id, username, timest, failedatt) 
VALUES ('John', '$username', '[email protected]','asdfasdf')"; 
$conn->query($sql); 
    header("location: index.php"); 
} 
$conn->close(); 
?> 
+0

打印您的$ sql,然後嘗試在phpmyadmin控制檯中查詢,看看會發生什麼 –

+0

您插入「約翰」對id字段,也許這就是產生錯誤。你可以打印insert sql並嘗試在phpmyadmin中運行。它會顯示你的SQL查詢中的錯誤究竟在哪裏。 –

+0

@Michael Dela Cruz:id字段是否自動增加? –

回答

0

$用戶名假設u盤Id字段作爲自動遞增

變化從

$sql = "INSERT INTO logattempt (id, username, timest, failedatt) 
VALUES ('John', '$username', '[email protected]','asdfasdf')"; 

$sql = "INSERT INTO logattempt (id, username, timest, failedatt) 
VALUES (null, '$username', '[email protected]','asdfasdf')";