gpt4 book ai didi

javascript - PHP 变量回显为空,但它包含 $_POST ["variable"] 回显出正确的值

转载 作者:行者123 更新时间:2023-11-28 17:39:23 25 4
gpt4 key购买 nike

问题是,当我为 ajax 中发布的变量的变量赋值为 $_POST["user"] 时,它没有向我显示任何内容。但是当我回显 $_POST["variable"] 时,它显示了正确的值。我想知道怎么可能?它发生在所有发布的变量上。

因此,我的用户名检查(如果条件)总是说需要 3-20 个字符,但它从来都不是真的,因为变量由于某种原因具有空值。

在我的网站上运行,直到问题解决: http://artisticdesigning.com/signup.php

<?php
if(isset($_POST["user"]))
{
include_once("Includes/database_link.php");

$first = $_POST["first"];
$last = $_POST["last"];
$email = $_POST["email"];
$userid = $_POST["user"];
$password = $_POST["password"];
$gender = $_POST["gender"];

$ip = preg_replace("#[^0-9.]#", "", getenv('REMOTE_ADDR'));

$sql = "SELECT id from users WHERE username='$userid' LIMIT 1";
$query = mysqli_query($cnctn, $sql);
$noofusers = mysqli_num_rows($query);

$sql = "SELECT id from users WHERE email='$email' LIMIT 1";
$query = mysqli_query($cnctn, $sql);
$noofemails = mysqli_num_rows($query);

if($first = "" || $last = "" || $email = "" || $password = "" || $userid = "" || $gender = "")
{
echo "Form submission is missing values.";
exit();
}
else if($noofusers > 0)
{
echo "The username you entered is already taken.";
exit();
}
else if($noofemails > 0)
{
echo "Someone is already using this email address.";
exit();
}
else if(strlen($userid) < 3 || strlen($userid) > 20)
{
echo "Username should be 3-20 characters long.";
exit();
}
else if(is_numeric($userid[0]))
{
echo "Username cannot begin with a number";
exit();
}
else
{
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);

$sql = "INSERT INTO users (first, last, email, username, password, gender, ip, signup, lastlogin, notescheck) values('$first', '$last', '$email', '$userid', '$password', '$gender', '$ip', now(), now(), now())";
$query = mysqli_query($cnctn, $sql);
$uid = mysqli_insert_id($cnctn);
?>

HTML:

<form id="signup-form">
<h2><a href="login.php">Login</a> &nbsp; or &nbsp;<u>Sign Up</u></h2>
<br>

<div id="signup-name">
<div class="signup-input-div">
<input class="signup-input" type="text" name="firstname" id="firstname" onMouseOver="signupPlaceholderCheck(0)" onMouseOut="signupPlaceholderCheck(0)" onFocus="signupPlaceholderCheck(0)" onBlur="signupPlaceholderCheck(0)" oninput="signupPlaceholderCheck(0)" required>
<label class="signup-placeholder">First Name</label>
</div>
<div class="signup-input-div">
<input class="signup-input" type="text" name="lastname" id="lastname" onMouseOver="signupPlaceholderCheck(1)" onMouseOut="signupPlaceholderCheck(1)" onFocus="signupPlaceholderCheck(1)" onBlur="signupPlaceholderCheck(1)" oninput="signupPlaceholderCheck(1)" required>
<label class="signup-placeholder">Last Name</label>
</div>
</div>

<br>

<div class="signup-input-div">
<input class="signup-input" type="email" id="email" name="email" maxlength="88" onMouseOver="signupPlaceholderCheck(2)" onMouseOut="signupPlaceholderCheck(2)" onFocus="signupPlaceholderCheck(2)" onBlur="signupPlaceholderCheck(2)" oninput="signupPlaceholderCheck(2)" required>
<label class="signup-placeholder">Your Email</label>
</div>

<br>

<div class="signup-input-div">
<span class="popup-box">

</span>
<input class="signup-input" type="text" id="username" name="username" maxlength="20" pattern=".{3,20}" title="3 characters minimum" autocomplete="off" onMouseOver="signupPlaceholderCheck(3)" onMouseOut="signupPlaceholderCheck(3)" onFocus="signupPlaceholderCheck(3)" oninput="signupPlaceholderCheck(3)">
<label class="signup-placeholder">Username</label>
</div>

<br>

<div class="signup-input-div">
<input class="signup-input" type="password" name="password" id="password" onMouseOver="signupPlaceholderCheck(4)" onMouseOut="signupPlaceholderCheck(4)" onFocus="signupPlaceholderCheck(4)" onBlur="signupPlaceholderCheck(4)" oninput="signupPlaceholderCheck(4)" required>
<label class="signup-placeholder">Password</label>
</div>

<br>

<div class="signup-input-div">
<span class="popup-box">

</span>

<input class="signup-input" type="password" name="confirm-password" id="confirm-password" onMouseOver="signupPlaceholderCheck(5)" onMouseOut="signupPlaceholderCheck(5)" onFocus="signupPlaceholderCheck(5)" oninput="signupPlaceholderCheck(5)" onBlur="signupPlaceholderCheck(5)" required>
<label class="signup-placeholder">Confirm your password</label>
</div>

<br>

<select required name="gender" id="gender">
<option>Gender</option>
<option value="m">Male</option>
<option value="f">Female</option>
<option value="o">Other</option>
</select>

<br /><br />
<span id="main-status"></span>
<br /><br />

<input type="submit" value="Sign Up" class="button" id="submit-button">
</form>

AJAX:

function signup()
{
var ajax = new XMLHttpRequest();
url = "signup.php";

var first = _("firstname").value;
var last = _("lastname").value;
var email = _("email").value;
var user = _("username").value;
var password = _("password").value;
var confirmpassword = _("confirm-password").value;
var gender = _("gender").value;
var btn = _("submit-button");

var status = $("popup-box");

if(first = "" || last == "" || email == "" || user == "" || password == "" || confirmpassword == "" || gender == "")
{
_("main-status").style.display="inline";
_("main-status").innerHTML="Fill out all of the form data!";
}

else if(password != confirmpassword)
{
status[1].style.display="inline";
status[1].innerHTML="Your Password fields do not match!";
}
else
{
ajax.open("POST", url, true);
ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
ajax.onreadystatechange =
function()
{
if(ajax.readyState == 4 && ajax.status == 200)
{
var data = ajax.responseText;
if(data != "signup_success")
{
_("main-status").display="inline";
_("main-status").innerHTML=data;
btn.style.display="inline";
}
else
{
_("signup-form").innerHTML="Thanks for Signing up "+first+", check your email inbox and junk mail box at <u>"+e+"</u> in a moment to complete the sign up process by activating your account. You will not be able to do anything on the site until you successfully activate your account.";
}
}
}
_("main-status").style.display="inline";
btn.style.display="none";
_("main-status").innerHTML="Please wait...";
ajax.send("first="+first+"&last="+last+"&user="+user+"&email="+email+"&password="+password+"&gender="+gender);
}
}

最佳答案

比较和赋值存在问题

if($first = "" || $last = "" || $email = "" || $password = "" || $userid = "" || $gender = "")
{
echo "Form submission is missing values.";
exit();
}

应该是

if($first == "" || $last == "" || $email == "" || $password == "" || $userid == "" || $gender == "")
{
echo "Form submission is missing values.";
exit();
}

请检查一下 http://sourcedaddy.com/php/differentiate-equal-signs.html

关于javascript - PHP 变量回显为空,但它包含 $_POST ["variable"] 回显出正确的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48327014/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com