Javascript未将信息发布到php
你好 请帮助我,我正在努力弄清楚为什么这个脚本不起作用,除了accountM之外,所有项目都在通过 PHP第一页代码段:Javascript未将信息发布到php,javascript,php,Javascript,Php,你好 请帮助我,我正在努力弄清楚为什么这个脚本不起作用,除了accountM之外,所有项目都在通过 PHP第一页代码段: <body> <div class="form"> <form name="registration" action="" id="register_form" method="post" autocomplete="new-password"> <input type="text" name="Name" placeholder=
<body>
<div class="form">
<form name="registration" action="" id="register_form" method="post" autocomplete="new-password">
<input type="text" name="Name" placeholder="Name" id="Name" autocomplete="new-password" required />
<input type="text" name="Surname" placeholder="Surname" id="Surname" autocomplete="new-password" required />
<input type="email" name="Email" placeholder="Email" id="Email" autocomplete="new-password" required />
<!-- The text and password here are to prevent FF from auto filling my login credentials because it ignores autocomplete="off" -->
<input type="text" style="display:none"/>
<input type="password" style="display:none"/>
<input type="password" name="Password" placeholder="Password" id="Password" autocomplete="new-password" required />
<div class="select">
<select name="Server" id="Server" onchange="server(this.value)">
<option value="">Select Server</option>
<option value="1">ZA02</option>
<option value="2">ZA04</option>
<option value="3">ZA05</option>
<?php
$getServer = $con->query("SELECT `Server`, `Name` FROM users.customers where `Server ID` = '0';");
$gsResult = mysqli_fetch_all($getServer);
for ($i = 0; $i < mysqli_num_rows($getServer); $i++) {
echo "
<option value=".$gsResult[$i][0].">".$gsResult[$i][1]."</option>
";
} ?>
</select>
<div class="select_arrow"></div>
</div>
<div class="select">
<select id='customer' name='Company'>
<option value=''>Select Customer</option>
</select>
<div class="select_arrow"></div>
</div>
<div class="select">
<select id="accountM" name="accountM">
<option value="">Select AM</option>
<option value="Tyron Lecki">Tyron Lecki</option>
<option value="Kaamilah Achmat">Kaamilah Achmat</option>
<option value="Siddharth Bawa">Siddharth Bawa</option>
</select>
<div class="select_arrow"></div>
</div>
<br>
<br>
<div syle="padding-bottom: 10px;">
<label for="cbox" style="color: #2f2f2f; float: left; margin-top: 10px; padding-right: 10px" >Premium</label>
<input id="cbox" type="checkbox" name="premium" id="Premium" value="yes"/>
</div>
<input type="button" id="submit" name="submit" value="Register" />
<br>
<div id="loading">
<p></p>
<p style="margin-left: 15px">Please Wait...</p>
<img src="images/hrs2.gif"/>
</div>
</form>
</div>
if (($_POST['name']=='')
||($_POST['surname']=='')
||($_POST['email']=='')
||($_POST['password']=='')
||($_POST['company']=='')
||($_POST['server']=='')
||($_POST['accountM']=='')) {
echo "Please fill in all fields";
} else {
// some other code
}
PHP第二页代码段:
<body>
<div class="form">
<form name="registration" action="" id="register_form" method="post" autocomplete="new-password">
<input type="text" name="Name" placeholder="Name" id="Name" autocomplete="new-password" required />
<input type="text" name="Surname" placeholder="Surname" id="Surname" autocomplete="new-password" required />
<input type="email" name="Email" placeholder="Email" id="Email" autocomplete="new-password" required />
<!-- The text and password here are to prevent FF from auto filling my login credentials because it ignores autocomplete="off" -->
<input type="text" style="display:none"/>
<input type="password" style="display:none"/>
<input type="password" name="Password" placeholder="Password" id="Password" autocomplete="new-password" required />
<div class="select">
<select name="Server" id="Server" onchange="server(this.value)">
<option value="">Select Server</option>
<option value="1">ZA02</option>
<option value="2">ZA04</option>
<option value="3">ZA05</option>
<?php
$getServer = $con->query("SELECT `Server`, `Name` FROM users.customers where `Server ID` = '0';");
$gsResult = mysqli_fetch_all($getServer);
for ($i = 0; $i < mysqli_num_rows($getServer); $i++) {
echo "
<option value=".$gsResult[$i][0].">".$gsResult[$i][1]."</option>
";
} ?>
</select>
<div class="select_arrow"></div>
</div>
<div class="select">
<select id='customer' name='Company'>
<option value=''>Select Customer</option>
</select>
<div class="select_arrow"></div>
</div>
<div class="select">
<select id="accountM" name="accountM">
<option value="">Select AM</option>
<option value="Tyron Lecki">Tyron Lecki</option>
<option value="Kaamilah Achmat">Kaamilah Achmat</option>
<option value="Siddharth Bawa">Siddharth Bawa</option>
</select>
<div class="select_arrow"></div>
</div>
<br>
<br>
<div syle="padding-bottom: 10px;">
<label for="cbox" style="color: #2f2f2f; float: left; margin-top: 10px; padding-right: 10px" >Premium</label>
<input id="cbox" type="checkbox" name="premium" id="Premium" value="yes"/>
</div>
<input type="button" id="submit" name="submit" value="Register" />
<br>
<div id="loading">
<p></p>
<p style="margin-left: 15px">Please Wait...</p>
<img src="images/hrs2.gif"/>
</div>
</form>
</div>
if (($_POST['name']=='')
||($_POST['surname']=='')
||($_POST['email']=='')
||($_POST['password']=='')
||($_POST['company']=='')
||($_POST['server']=='')
||($_POST['accountM']=='')) {
echo "Please fill in all fields";
} else {
// some other code
}
当使用这个时,我不断得到“请填写所有字段”,我发现只有accountM变量没有传递给第二个脚本
编辑:
以下是AJAX脚本:
function server(str) {
if (str == "") {
document.getElementById("customer").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("customer").innerHTML = this.responseText;
}
};
xmlhttp.open("GET","customer.php?q="+str,true);
xmlhttp.send();
}
}
customer.php:
<?php
include("db.php");
$q = intval($_GET['q']);
$result = $con->query("SELECT * from users.customers where `Server ID` = '".$q."' order by Name");
echo "<option value=''>Select Customer</option>";
while ($row = mysqli_fetch_array($result)) {
echo "<option value='" . htmlentities($row['Name'], ENT_QUOTES) . "'>"
. htmlentities($row['Name'], ENT_QUOTES)
. "</option>";
}
mysqli_close($con);
在上面的所有注释之后,似乎server()
函数损坏了DOM,那么您的
标记不再有效,无法发送。尝试使用以下方法保护PHP发送的HTML:
在上面的所有注释之后,似乎server()
函数损坏了DOM,那么您的
标记不再有效,无法发送。尝试使用以下方法保护PHP发送的HTML:
该症状表明选项值是问题的原因,因为它们没有被引用和/或转换为html实体,这会导致dom中断。我认为有两个地方会出现问题:
以您的形式:
<option value="">Select Server</option>
<option value="1">ZA02</option>
<option value="2">ZA04</option>
<option value="3">ZA05</option>
<?php
if($result=$con->query("SELECT `Server`,`Name` FROM users.customers WHERE `Server ID`=0;")){
while($row=$result->fetch_assoc()){
echo "<option value=\"",htmlentities($row['Server'],ENT_COMPAT),"\">",htmlentities($row['Name'],ENT_COMPAT),"</option>";
}
}else{
echo "<option>ERROR</option>"; // just for the sake of debugging
}
?>
我完全未经验证的建议
@你的表格
<body>
<div class="form">
<form id="register" autocomplete="new-password">
<input type="text" name="Name" placeholder="Name" id="Name" autocomplete="new-password" required />
<input type="text" name="Surname" placeholder="Surname" id="Surname" autocomplete="new-password" required />
<input type="email" name="Email" placeholder="Email" id="Email" autocomplete="new-password" required />
<!-- The text and password here are to prevent FF from auto filling my login credentials because it ignores autocomplete="off" -->
<input type="text" style="display:none"/>
<input type="password" style="display:none"/>
<input type="password" name="Password" placeholder="Password" id="Password" autocomplete="new-password" required />
<div class="select">
<select name="Server" id="Server">
<option value="">Select Server</option>
<option value="1">ZA02</option>
<option value="2">ZA04</option>
<option value="3">ZA05</option>
<?php
if($result=$con->query("SELECT `Server`,`Name` FROM users.customers WHERE `Server ID`=0;")){
while($row=$result->fetch_assoc()){
echo "<option value=\"",htmlentities($row['Server'],ENT_COMPAT),"\">",htmlentities($row['Name'],ENT_COMPAT),"</option>";
}
}else{
echo "<option>ERROR</option>"; // just for the sake of debugging
}
?>
</select>
<div class="select_arrow"></div>
</div>
<div class="select">
<select id="Company" name="Company">
<option value=''>Select Customer</option>
</select>
<div class="select_arrow"></div>
</div>
<div class="select">
<select id="AccountM" name="AccountM">
<option value="">Select AM</option>
<option value="Tyron Lecki">Tyron Lecki</option>
<option value="Kaamilah Achmat">Kaamilah Achmat</option>
<option value="Siddharth Bawa">Siddharth Bawa</option>
</select>
<div class="select_arrow"></div>
</div>
<br><br>
<div syle="padding-bottom: 10px;">
<label for="cbox" style="color: #2f2f2f; float: left; margin-top: 10px; padding-right: 10px" >Premium</label>
<input id="cbox" type="checkbox" name="Premium" id="Premium" value="yes"/>
</div>
<input type="button" id="Submit" value="Register" />
<br>
<div id="status"></div>
</form>
</div>
</body>
选择服务器
ZA02
ZA04
ZA05
选择客户
选择AM
蒂龙·莱基
卡米拉·阿赫马特
西德哈特巴瓦酒店
保险费
@你的.js文件
$(document).ready(function(){
$("#Server").change(function(){
$("#status").html("<p></p><p style=\"margin-left:15px\">Please Wait...</p><img src=\"images/hrs2.gif\"/>");
$.get("customer.php", {q:this.value}, function(response){
$("#Company").html(response);
$("#status").html("");
});
});
$("#Submit").click(function(){
e.preventDefault();
$("#status").html("<p></p><p style=\"margin-left:15px\">Please Wait...</p><img src=\"images/hrs2.gif\"/>");
$.post('register.php', $(this).serialize(), function(response){
$("#status").html(response);
});
});
});
$(文档).ready(函数(){
$(“#服务器”).change(函数(){
$(“#status”).html(“请稍候…
”;
$.get(“customer.php”,{q:this.value},函数(响应){
$(“#公司”).html(回复);
$(“#status”).html(“”);
});
});
$(“#提交”)。单击(函数(){
e、 预防默认值();
$(“#status”).html(“请稍候…
”;
$.post('register.php',$(this).serialize(),函数(响应){
$(“#status”).html(回复);
});
});
});
@customer.php
<?php
include("db.php");
if(empty($_GET['q'])){
echo "<option value=''>Select Population Error</option>";
}else{
if($result=$con->query("SELECT `Name` from users.customers WHERE `Server ID`=".intval($_GET['q'])." ORDER BY `Name`"){
echo "<option value=''>Select Customer</option>";
while($row=$result->fetch_assoc()){
echo "<option>",htmlentities($row['Name'],ENT_COMPAT),"</option>";
}
}
?>
该症状表明选项值是问题的原因,因为它们没有被引用和/或转换为html实体,这会导致dom中断。我认为有两个地方会出现问题:
以您的形式:
<option value="">Select Server</option>
<option value="1">ZA02</option>
<option value="2">ZA04</option>
<option value="3">ZA05</option>
<?php
if($result=$con->query("SELECT `Server`,`Name` FROM users.customers WHERE `Server ID`=0;")){
while($row=$result->fetch_assoc()){
echo "<option value=\"",htmlentities($row['Server'],ENT_COMPAT),"\">",htmlentities($row['Name'],ENT_COMPAT),"</option>";
}
}else{
echo "<option>ERROR</option>"; // just for the sake of debugging
}
?>
我完全未经验证的建议
@你的表格
<body>
<div class="form">
<form id="register" autocomplete="new-password">
<input type="text" name="Name" placeholder="Name" id="Name" autocomplete="new-password" required />
<input type="text" name="Surname" placeholder="Surname" id="Surname" autocomplete="new-password" required />
<input type="email" name="Email" placeholder="Email" id="Email" autocomplete="new-password" required />
<!-- The text and password here are to prevent FF from auto filling my login credentials because it ignores autocomplete="off" -->
<input type="text" style="display:none"/>
<input type="password" style="display:none"/>
<input type="password" name="Password" placeholder="Password" id="Password" autocomplete="new-password" required />
<div class="select">
<select name="Server" id="Server">
<option value="">Select Server</option>
<option value="1">ZA02</option>
<option value="2">ZA04</option>
<option value="3">ZA05</option>
<?php
if($result=$con->query("SELECT `Server`,`Name` FROM users.customers WHERE `Server ID`=0;")){
while($row=$result->fetch_assoc()){
echo "<option value=\"",htmlentities($row['Server'],ENT_COMPAT),"\">",htmlentities($row['Name'],ENT_COMPAT),"</option>";
}
}else{
echo "<option>ERROR</option>"; // just for the sake of debugging
}
?>
</select>
<div class="select_arrow"></div>
</div>
<div class="select">
<select id="Company" name="Company">
<option value=''>Select Customer</option>
</select>
<div class="select_arrow"></div>
</div>
<div class="select">
<select id="AccountM" name="AccountM">
<option value="">Select AM</option>
<option value="Tyron Lecki">Tyron Lecki</option>
<option value="Kaamilah Achmat">Kaamilah Achmat</option>
<option value="Siddharth Bawa">Siddharth Bawa</option>
</select>
<div class="select_arrow"></div>
</div>
<br><br>
<div syle="padding-bottom: 10px;">
<label for="cbox" style="color: #2f2f2f; float: left; margin-top: 10px; padding-right: 10px" >Premium</label>
<input id="cbox" type="checkbox" name="Premium" id="Premium" value="yes"/>
</div>
<input type="button" id="Submit" value="Register" />
<br>
<div id="status"></div>
</form>
</div>
</body>
选择服务器
ZA02
ZA04
ZA05
选择客户
选择AM
蒂龙·莱基
卡米拉·阿赫马特
西德哈特巴瓦酒店
保险费
@你的.js文件
$(document).ready(function(){
$("#Server").change(function(){
$("#status").html("<p></p><p style=\"margin-left:15px\">Please Wait...</p><img src=\"images/hrs2.gif\"/>");
$.get("customer.php", {q:this.value}, function(response){
$("#Company").html(response);
$("#status").html("");
});
});
$("#Submit").click(function(){
e.preventDefault();
$("#status").html("<p></p><p style=\"margin-left:15px\">Please Wait...</p><img src=\"images/hrs2.gif\"/>");
$.post('register.php', $(this).serialize(), function(response){
$("#status").html(response);
});
});
});
$(文档).ready(函数(){
$(“#服务器”).change(函数(){
$(“#status”).html(“请稍候…
”;
$.get(“customer.php”,{q:this.value},函数(响应){
$(“#公司”).html(回复);
$(“#status”).html(“”);
});
});
$(“#提交”)。单击(函数(){
e、 预防默认值();
$(“#status”).html(“请稍候…
”;
$.post('register.php',$(this).serialize(),函数(响应){
$(“#status”).html(回复);
});
});
});
@customer.php
<?php
include("db.php");
if(empty($_GET['q'])){
echo "<option value=''>Select Population Error</option>";
}else{
if($result=$con->query("SELECT `Name` from users.customers WHERE `Server ID`=".intval($_GET['q'])." ORDER BY `Name`"){
echo "<option value=''>Select Customer</option>";
while($row=$result->fetch_assoc()){
echo "<option>",htmlentities($row['Name'],ENT_COMPAT),"</option>";
}
}
?>
请向我们显示表单代码(表单HTML)请提供更多的HTML标记,除了不发布之外,脚本的其余部分是否按预期工作?单击提交时是否更改选择值?因为您选择的默认值是空字符串,因此此$\u POST['accountM']=''
将是true
!你看到我的评论了吗?下一个澄清。。。这些服务器值中有任何一个会破坏dom吗?请触发server()
,然后向我们显示源代码的相关部分。请向我们显示表单代码(表单HTML)请提供更多的HTML标记,除了它没有发布外,脚本的其余部分是否按预期工作?单击提交时是否更改选择值?因为您选择的默认值是空字符串,因此此$\u POST['accountM']=''
将是true
!你看到我的评论了吗?下一个澄清。。。这些服务器值中有任何一个会破坏dom吗?请触发server()
,然后向我们展示源代码的相关部分。感谢您的解释,我添加了您的代码(替换customer.php文件中的代码),但它仍然不起作用。这是转储数组(6){[“name”]=>string(4)“Piet”[“姓氏”]=>string(7)“Pompies”[“email”]=>string(16)”piet@example.com“[“密码”]=>string(4)“测试”[“公司”]=>string(9)“Eminerals”[“服务器”]=>string(1)“3”}@Dreamsword981所以,请不要选择任何服务器并发布您的信息