我尝试这个PHP代码(我已经阅读过关于sql注入)但显然它没有运行,没有错误信息或其他任何东西......
<?php
function SignIn(){
session_start();
require_once("dbConnection.php");
if(isset($_POST['submit'])){
$db_handle = new DBConnection();
$username = $_POST["username"];
if(filter_var($username, FILTER_VALIDATE_EMAIL)===true && strpos(explode('@',$username),"studio.unibo.it")===true){
$query = $db_con->prepare("SELECT * FROM studenti_in_sessione
WHERE Username=:username");
$query->execute(array(":username"=>$username));
$row = $query->fetch(PDO::FETCH_ASSOC);
$count = $query->rowCount();
if($row['Username']==$username){
echo "<script language = javascript>
alert(\"Autenticazione riuscita,Le invieremo nella mail istituzionale un codice univoco di autenticazione.\");
window.history.go(-1);
</script>";
$querySession = $db_con->prepare("SELECT Nome, Cognome, Matricola FROM studenti_in_sessione
WHERE Username:=username");
$querySession->execute(array(":username"=>$username));
$rowStud = $querySession->fetch(PDO::FETCH_ASSOC);
$exit = array_values($rowStud);
$queryInsert = $db_con->prepare("INSERT INTO studente (Nome, Cognome, Matricola, Username, Codice) VALUES('".$exit[0]."',
'".$exit[1]."','".$exit[2]."','".$username."');");
$resultInsert = $queryInsert->execute();
sendCode($username);
}
}}else{
echo "<script language = javascript>
alert(\"L'indirizzo deve essere @studio.unibo.it.\");
window.history.go(-1);
</script>";
}
if(isset($_POST['submit'])){
SignIn();
}
?>
这是html表格
<div class="box-header">
<h2>Login</h2>
</div>
<form name="form" class="form" method="POST">
<label for="username">Username</label>
<br/>
<input type="text" id="username" name="username">
<input name="submit" id="submit" type="submit" value="Login">
</div>
最后是script.js
$('document').ready(function()
{
/* validation */
$(".form").validate({
rules:
{
user_email: {
required: true,
email: true
},
},
messages:
{
user_email: "please enter your email address",
},
submitHandler: submitForm
});
/* validation */
/* login submit */
function submitForm()
{
var data = $(".form").serialize();
$.ajax({
type : 'POST',
url : '../Slide_upload/database/signIn.php',
data : data,
success : function(response){
if(response=="ok"){
}
else{
}
}
});
return false;
}
/* login submit */
});
我可能犯了错误,但我无法弄明白...
答案 0 :(得分:0)
当然,您缺少一个括号来关闭未执行的功能。 在行
之前添加它if(isset($_POST['submit'])){
SignIn();
}
这将使您的函数调用工作。