js代码:
function signin() {
var name = $('#name').val();
var password = $('#password').val();
dataVal = {
username: name,
userpassword: password
};
$.ajax({
url: 'verifyOld.php',
type: 'GET',
data: dataVal,
success: function(msg) {
alert(msg);
}
});
}
PHP代码:
<?php
$username = $_GET['username'];
$userpassword = $_GET['userpassword'];
$link = mysqli_connect("localhost","root","1009976636",'blog');
if(!$link)
{
$output = 'Unable to connect to the database server.';
echo $output;
exit();
}
if(!mysqli_set_charset($link,'utf8'))
{
$output = 'Unable to set database connection encoding.';
echo $output;
exit();
}
$sql = ("select password from user where username = '$username'");
$result = mysqli_query($link, $sql);
if (mysqli_num_rows($result) > 0) {
if($userpassword == mysqli_fetch_assoc($result)["password"])
{
// $url = 'homepage.html';
// header("Location: $url");
// echo "login successuflly";
// if(isset($url))
// {
// header('Location:'.$url);
// exit();
// }
// $url = "homepage.html";
// echo "<script language='javascript' type='text/javascript'>";
// echo "window.location.href='$url'";
// echo "</script>";
}
else
echo "The username and/or password you specified are not correct.";
}
else {
echo "The username does not exist!";
}
?>
还望大神不吝赐教。