我有一个使用jQuery POST函数的表单,该表单使用switch函数将变量传递给PHP文件。 POSTed变量之一称为“指标” ...该变量由开关评估,并根据其值执行不同的大小写。
我已经验证了前端的所有功能,但是由于某种原因,我无法从PHP文件获得任何输出。 PHP文件中的开关堆栈可能工作正常,但是我只是看不到前端的任何输出。尝试从后端进行一个简单的变量转储,仍然是nada。有什么想法吗?谢谢大家
我已经将代码包含在我的表单中,提交表单时调用了jQuery函数,以及后端PHP开关:
FORM:
<form id="createAcc" onsubmit="return createAccResults();" style="height: 800px; top: 53%;">
<input type="submit" id="createAccSubmit" name="createAccSubmit" value="Submit"></br>
<h3 id="usernameTxt">Create username</h3>
<p id="instructions">(Any length & combo of letters and numbers)</p>
<input id="userName" name="userName" type="text" value=""></br>
<h3 id="emailTxt">Enter email address.</h3>
<input id="email" name="email" type="text" value=""></br>
<h3 id="pwTxt">Create password</h3>
<p id="instructions">(Must be min. 6 char long & contain at least 1 number, 1 lowercase & 1 uppercase letter)</p>
<input id="password" name="password" type="password" value=""></br>
<h3 id="pwConfTxt">Confirm password</h3>
<input id="passwordConf" name="passwordConf" type="password" value="">
<h3 id="secQuestion1" style="font-family: cursive; font-style: italic; color: white;">Security Question 1:</h3>
<p id="question1" style="font-family: cursive; font-style: italic; color: white;">What is your childhood nickname?</p>
<input id="sQ1" name="sQ1" type="text" value="" style="width: 350px; height: 30px; border-radius: 20px;"></br>
<h3 id="secQuestion2" style="font-family: cursive; font-style: italic; color: white;">Security Question 2:</h3>
<p id="question2" style="font-family: cursive; font-style: italic; color: white;">Where were you born?</p>
<input id="sQ2" name="sQ2" type="text" value="" style="width: 350px; height: 30px; border-radius: 20px;"></br>
</form>
JQUERY POST:
function createAccResults() {
$(document).ready(function() {
var pw = document.getElementById("password").value;
var indicator = 2;
var eml = document.getElementById("email").value;
var inpU = document.getElementById("userName").value;
var inpPC = document.getElementById("passwordConf").value;
conditionss = /(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,}/,
conditions = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/,
conditionU = /^[a-zA-Z0-9]+$/;
if(!(conditionss.test(pw)) || !(conditions.test(eml)) || !(conditionU.test(inpU)) || !(pw==inpPC)) {
document.getElementById('userName').value = "";
document.getElementById('email').value = "";
document.getElementById('password').value = "";
document.getElementById('passwordConf').value = "";
alert("Please complete form correctly");
} else {
$("#createAcc").css("display","none");
$("#revealAcc").css("display","none");
$("#uploadTrg").show();
$.post("updateProfile.php", {un: inpU, pw: pw, eml: eml, indicator: indicator},
function(returned) {
document.getElementById("uploadTrg").innerHTML = returned;
});
};
});
return false;
};
PHP SWITCH:
$UsrN = $_POST['un'];
$eml = $_POST['eml'];;
$pswrd = $_POST['pw'];
$usernameMatch = preg_match('/^[a-zA-Z0-9]+$/', $UserN);
$emailMatch = preg_match('/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/', $eml);
$pwMatch = preg_match('/(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,}/', $pswrd);
$query = "SELECT email FROM accounts WHERE username='$UserN' OR email='$eml' OR password='$pswrd'";
$results = $pdo->query($query);
$indicator = $_POST['indicator'];
switch($indicator) {
case 2:
if($results == 0 && $pwMatch == 1 && $emailMatch == 1 && $usernameMatch == 1) {
$query4 = "INSERT INTO accounts (username, email, password, about) VALUES ('$userN', '$eml', '$pswrd', 'Add a little about yourself')";
$results4 = $pdo->query($query4);
$message = "Account created successfully! Please login";
} else if ($usernameMatch === false || $emailMatch === false || $pwMatch === false) {
$message = "Please complete form correctly";
} else {
$message = "Account info already taken";
}
echo "<p style='color: white; font-family: cursive; font-size: 35px; text-align: center;'>";
echo $message;
echo "</p>";
break;
case 3:
SOME CODE THAT'S IRRELEVANT; PERTAINS TO ANOTHER JQUERY POST FUNCTION THAT WORKS FINE
case 5:
SOME CODE THAT'S IRRELEVANT; PERTAINS TO ANOTHER JQUERY POST FUNCTION THAT WORKS FINE
}