我的代码应该引用我相信的 login_process.php 页面,但它没有返回任何内容。无论是错误消息还是成功消息。我看不出有什么问题,并尝试了一些不同的方法来使其正常工作。isset($_POST['login'])
当我在它显示的内容之外回显某些内容时。但在里面,什么都没有。这就是让我相信这是一个问题......但我不太确定。
PHP代码:
<?php
ob_start();
require 'db.php';
if(isset($_POST['login'])) {
$date = date("F j, Y, g:i a");
$username = $_POST['username'];
$password = sha1($_POST['password']);
// VARS
$username = stripslashes($username);
$username = strip_tags($username);
$username = mysql_real_escape_string($username);
$password = stripslashes($password);
$password = strip_tags($password);
$password = mysql_real_escape_string($password);
// SELECT DB
$sql = "SELECT * FROM `users` WHERE `username` = '$username' AND `password` = '$password'";
$result = mysql_query($sql) or die ( mysql_error() );
if (mysql_num_rows($result) != 0) {
session_start();
$row = mysql_fetch_array($result);
$_SESSION['loggedIn'] = "true";
$_SESSION['username'] = $username;
$_SESSION['ip'] = $_SERVER['REMOTE_ADDR'];
header("refresh: 2; bet_gg.php");
echo '<div class="alert success hideit" style="width: 50%;">
<p> Success. You will be redirected.</p>
<span class="close"></span></div>';
} else {
$_SESSION['loggedIn'] = "false";
echo '
<div class="alert error hideit" style="width: 50%;">
<p>There was an error with your log-in.</p>
<span class="close"></span>
</div><!-- End error -->';
}
}
?>
HTML 代码:
<form action="login_process.php" method="POST" id="myForm">
<div class="two-thirds column">
<div class="who">
<h2 class="title">Log-In<span class="line"></span></h2>
<div class="form-box">
<label>Username <small>(required)</small></label>
<input type="text" name="username" class="text">
</div><!-- End Box -->
<div class="form-box">
<label>Password <small>(required)</small></label>
<input type="password" name="password" class="text">
</div><!-- End Box -->
<div class="form-box">
<button type="submit" clas="button medium color sub" name="login" class="button medium color sub" value="Log-In">Log-In</button>
</div><!-- End Box -->
<br /><br />
</div>
</div><!-- End who we are -->
<span id="result"></span>
</form>
jQuery代码:
$("#sub").click( function() {
$.post( $("#myForm").attr("action"),
$("#myForm :input").serializeArray(),
function(info){ $("#result").html(info);
});
});
$("#myForm").submit( function() {
return false;
});