Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
不使用ajax传递给php的值_Php_Mysql_Jquery - Fatal编程技术网

不使用ajax传递给php的值

不使用ajax传递给php的值,php,mysql,jquery,Php,Mysql,Jquery,我有以下脚本: <script type="text/javascript" > $('form').each(function() { $(this).on('submit', function() { var first_firstname = $(".first_firstname", this).val(); var first_lastname = $(".first_lastname", this).val(); var second_firstname =

我有以下脚本:

<script type="text/javascript" >

$('form').each(function() {
    $(this).on('submit', function() {

var first_firstname = $(".first_firstname", this).val();
var first_lastname = $(".first_lastname", this).val();
var second_firstname = $(".second_firstname", this).val();
var second_lastname = $(".second_lastname", this).val();
var TeamName = $(".TeamName", this).val();
var dataString = 'first_firstname='+ first_firstname + '&first_lastname=' + first_lastname +
'&second_firstname=' + second_firstname + '&second_lastname=' + second_lastname + '&TeamName=' + TeamName;

 $.ajax({
type: "POST",
url: "data.php",
data: dataString,
success: function(){
window.setTimeout(function(data)
{
$('#propspectDiv').html('Team Name Added!');
$('#data').css("display","block");
$('#data').html(data);
}, 2000);
}

});

return false;
});

</script>

$('form')。每个(函数(){
$(this).on('submit',function()){
var first_firstname=$(“.first_firstname”,this.val();
var first_lastname=$(“.first_lastname”,this.val();
var second_firstname=$(“.second_firstname”,this.val();
var second_lastname=$(“.second_lastname”,this).val();
var TeamName=$(“.TeamName”,this.val();
var dataString='first\u firstname='+first\u firstname+'&first\u lastname='+first\u lastname+
“&second_firstname=”+second_firstname+”&second_lastname=“+second_lastname+”&TeamName=”+TeamName;
$.ajax({
类型:“POST”,
url:“data.php”,
数据:dataString,
成功:函数(){
设置超时(函数(数据)
{
$('propspectDiv').html('Team Name Added!');
$(“#数据”).css(“显示”、“块”);
$('#data').html(数据);
}, 2000);
}
});
返回false;
});
下面的php使用mysql数据库在一个页面上生成许多表单

<?php    

echo '<table class="greensmalltbl" cellspacing="10px" cellpadding="5px"><div id="propspectDiv"></div>';

    for ($i=1,  $o=$totalEntrants; $i<=$half; $i++, $o=$o-1) {

    $formid = $i;


echo "<div style='border:3px;'><form action='' method='post'>
<tr><td><input type='text' name='first_firstname' id='first_firstname' value='$firstName[$i]' />
<input type='text' name='first_lastname' id='first_lastname' value='$lastName[$i]' />
  Skill Level : ".$skill[$i]."</td></tr>";
echo "<tr><td>WITH</td></tr>";
echo "<tr><td><input type='text' name='second_firstname' id='second_firstname' value='$firstName[$o]' />
<input type='text' name='second_lastname' id='second_lastname' value='$lastName[$o]' /> Skill Level ".$skill[$o]."</td></tr>";
echo "<tr><td>Enter Team Name : <input type='text' name='TeamName' id='TeamName' value='' />
<input type='submit' name='submit' value='Submit'></form></td></tr>";

    }

echo '</table>';

我想用每个表单中的团队名称更新db表

问题是只有第一个表单输入被传递,所有其他表单什么也不做 我尝试过ajax代码的许多变体,但都没有成功。
有人能在这里找到问题吗?

此行不会返回表单

var parent = $(this).parent('form');
因为您的提交按钮被包装在
tr
td
标记中。请清除这些标记(它们仍然无效,因为您没有在
表中使用它们),或者将代码更新为:

var parent = $(this).closest('form');
closest()
搜索元素的所有祖先,并返回选择器的第一个匹配项。 请在此处查看文档:

或者,如果您的页面中只有一个表单,您可以选择:

var parent = $('form');
::编辑::

好的。忘记上面的所有内容。似乎您在代码的后面甚至没有使用父变量。 更重要的问题是,即使您正在捕获表单提交按钮上的单击事件,您可能真正想要做的是捕获表单的提交事件

var parent = $(this).parent('form');
因此,将第一行代码更改为:

$('form').on('submit', function() {
此外,在HTML中,代码无效

<form action'' method='post' id='$formid'>

live已被取消使用标题我对所有ajax和jquery都不熟悉,但我在('click',function()上将其更改为$('input[type=“submit”]){现在,即使是第一个表单也不能完全工作for语句似乎工作正常我的问题是传递每个表单的值Jules感谢您的响应我已经根据您的建议编辑了我的代码,但是在循环生成的第一个表单工作正常但没有其他表单之前,没有任何工作正常你有没有通过验证程序运行你的HTML代码?你有没有收到firebug的任何警告?