我对PHP,HTML,jQuery非常新,我需要一些帮助。当我点击提交按钮时,我需要激活一个php脚本。我已设置将我的会话设置为我的用户名和ID。如果输入的信息与数据库相同,我真正需要的是一种更新或附加p标签到我的div的方法。基于if语句的jQuery
这里是我的代码:
<div class="modal-footer">
<input type="submit" name="sumbit" value="Login" class="btn btn-primary" />
<?php
if (isset($_POST["username"])) {
$username = $_POST["username"];
$password = $_POST["password"];
$sql = "select * from users where username = '$username' and password = '$password' limit 1";
$res = mysql_query($sql) or die(mysql_error());
if (mysql_num_rows($res)) {
$row = mysql_fetch_assoc($res);
$_SESSION["uid"] = $row["id"];
$_SESSION["username"] = $row["username"];
header("Location: index.php");
} else {
?>
//I want to add the text to my modal body above this code
<?php
}
}
?>
</div>
此外,如果你还没有注意到已经我使用的引导。
我的主要问题是我不知道如何运行PHP来检查信息是否正确,如果没有模态关闭,如果是的话。
改为使用xmlhttprequest – Ghost
您应该[停止使用mysql_函数](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php),因为他们已经从PHP中删除。您还应该使用[password_hash](http://php.net/manual/en/function.password-hash.php)来确保您的密码。最后,[你的代码是开放的SQL注入](http://stackoverflow.com/documentation/php/275/using-a-database/2685/preventing-sql-injection-with-parametrized-queries) – Machavity