无法在单个html页面上提交多个表单

时间:2011-09-07 02:47:20

标签: php html forms

我在一个文件上遇到表单问题。 问题是,当我点击提交时...它提交了第一个表单数据而不是人填写的表单,即使您从下面的代码中可以看到我为每个表单指定了某个ID。

我正在使用php文件将数据提交给mysql

这是我的代码:

case 'upd_chpt':
if($_POST['does'] == 'upd_chpt')
{
    $chId = $_POST['chId'];
    $name = $_POST['name'];
    $nums = $_POST['nums'];
    $mngs = $_POST['mang'];
    $ch_trans = $_POST['ch_trans'];
    $ch_down = $_POST['ch_down'];
    $ch_translate = $_POST['ch_translate'];
    $ch_clean = $_POST['ch_clean'];
    $ch_editor = $_POST['ch_editor'];
    if(!empty($chId) && !empty($name) && !empty($nums) && !empty($mngs) && !empty($ch_trans))
    {
        $mnG = explode(',' , $mngs);
        $qup = $db->query("UPDATE chapter SET ch_name = '".$name."', chapter_num = '".$nums."', manga_id = '".$mnG[0]."', manga_title = '".$mnG[1]."', manga_name = '".$mnG[2]."', ch_down = '".$ch_down."', ch_translate = '".$ch_translate."', ch_clean = '".$ch_clean."', ch_editor = '".$ch_editor."', ch_trans = '".$ch_trans."' WHERE ch_Id = '".$chId."' ");
        if($qup)
        {
            echo "updated successfully";
        }
        else
        {
            echo "erorr ";
        }
    }
    else
    {
        echo "please fill all the fields !";
    }
}
break;

html代码:

<form id="edit_{$ch[ch].ch_Id}">
    <input type="hidden" name="chid" value="{$mn[mn].ch_Id}" />
    <label>chapter number</label>
    <input type="text" id="chaptr" name="chaptr" value="{$ch[ch].chapter_num}" class="short" />
    <label>chapter title </label>
    <input type="text" id="name" name="name" value="{$ch[ch].ch_name}" class="short" />
    <label>manga related to chapter</label>
    <select id="mansga" name="manga">
        {section name='mn' loop=$mng}
            <option value='{$mng[mn].mn_Id},{$mng[mn].mn_title},{$mng[mn].mn_name}' {if $mng[mn].mn_Id==$ch[ch].manga_id}selected="true" {/if}>
                {$mng[mn].mn_name}
            </option>
        {/section}
    </select>
    <label>chapter link</label>
    <input type="text" id="ch_down" name="ch_down" value="{$ch[ch].ch_down}" class="short" />
    <label>all credit goes to</label>
    <input type="text" id="ch_trans" name="ch_trans" value="{$ch[ch].ch_trans}" class="short" />
    <label>translated by</label>
    <input type="text" id="ch_translate" name="ch_translate" value="{$ch[ch].ch_translate}" class="short" />
    <label>cleaned by</label>
    <input type="text" id="ch_clean" name="ch_clean" value="{$ch[ch].ch_clean}" class="short" />
    <label>edited by</label>
    <input type="text" id="ch_editor" name="ch_editor" value="{$ch[ch].ch_editor}" class="short" />
    <label><input type="submit" class="submit" value="تعديل" /></label>
</form>

javascript:

$('[id^=edit_]').submit(function(){
    var id = $(this).attr('id').split('_')[1];
    var name = $('#name').val();
    var nums = $('#chaptr').val();
    var mang = $('#mansga').val();
    var ch_trans = $('#ch_trans').val();
    var ch_down = $('#ch_down').val();
    var ch_translate = $('#ch_translate').val();
    var ch_clean = $('#ch_clean').val();
    var ch_editor = $('#ch_editor').val();
    $.post("action.php", {does: 'upd_chpt' ,ch_trans:ch_trans, ch_down:ch_down, ch_translate:ch_translate , ch_clean:ch_clean , ch_editor:ch_editor , chId:id , name: name, nums: nums, mang:mang},function(m){
        alert(m);
    });
    return false
});

可以更改此代码吗?并且只有php + html没有javascript! ...因为我认为id =“”是问题

1 个答案:

答案 0 :(得分:0)

错误在第二行 {$ mn [mn] .ch_Id}应为{$ ch [ch] .ch_Id}