0
我一直在試圖弄清楚這已超過兩天,我正在遵循一個YouTube教程,基本登錄我的Android應用程序,但在此之前我想測試.php腳本。Php,MySql和Webform
我在想,我應該得到的成功,當我按下登錄按鈕,但我得到證書無效,我知道用戶名和密碼是正確的
下面是我的login.php腳本。
require("config.inc.php");
if (!empty($_POST)) {
//gets user's info based off of a username.
$query = "SELECT id, username, passwrd
FROM application_users
WHERE
username = :username
";
$query_params = array(
':username' => $_POST['username']
);
try {
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
}
catch (PDOException $ex) {
// For testing, you could use a die and message.
//die("Failed to run query: " . $ex->getMessage());
//or just use this use this one to product JSON data:
$response["success"] = 0;
$response["message"] = "Database Error1. Please Try Again!";
die(json_encode($response));
}
//This will be the variable to determine whether or not the user's information is correct.
//we initialize it as false.
$validated_info = false;
//fetching all the rows from the query
$row = $stmt->fetch();
echo $row;
if ($row) {
//if we encrypted the password, we would unencrypt it here, but in our case we just
//compare the two passwords
if ($_POST['password'] === $row['password']) {
$login_ok = true;
}
}
// If the user logged in successfully, then we send them to the private members-only page
// Otherwise, we display a login failed message and show the login form again
if ($login_ok) {
$response["success"] = 1;
$response["message"] = "Login successful!";
die(json_encode($response));
} else {
$response["success"] = 0;
$response["message"] = "Invalid Credentials!";
die(json_encode($response));
}
} else {
?>
<h1>Login</h1>
<form action="login.php" method="post">
Username:<br />
<input type="text" name="username" placeholder="username" />
<br /><br />
Password:<br />
<input type="password" name="password" placeholder="password" value="" />
<br /><br />
<input type="submit" value="Login" />
</form>
<a href="register.php">Register</a>
</form>
<?php
} ?>
所以當腳本加載和我輸入從遠程MySQL服務器的值,消息回來爲無效credentials.I只是想確保我的登錄成功之前我回頭看看android部分,這本身就是一個大問題。
您確定數據是通過發佈後操作發送的嗎? – Barry 2014-10-20 16:51:34
完成任何基本的調試? 'var_dump($ _ POST)'和'var_dump($ row)'會向你顯示你的表單和數據庫接受的是什麼樣的php。檢查字符串長度,檢查字符串內容等... – 2014-10-20 16:52:57
從來沒有真正做過任何使用PHP的調試,我應該在哪裏放置var_dump satements。 – 2014-10-20 16:55:46