输入类型=提交不返回任何内容

时间:2015-02-28 03:25:49

标签: php post submit form-submit

团队,你能帮帮我吗?我试图从表单中获取值以更改mysql上的值。这是一个需要值的销售操作,它将被放入数据库中。 我有一个复选框,允许用户根据此选择选择他想要出售的对象我正在创建一个新的表格,其中包含所选对象和值的POST方法。然而,这并不是我所需要的,我不知道如何将每个值与正确的对象相关联。你能帮忙吗 ?这是我坚持的部分,更具体地说是第二部分:

if(isset($_POST['publicar'])){//to run PHP script on submit
                if(!empty($_POST['check_list'])){

                    echo "<tr><td>Sites a Publicar</td><td>Valor</td></tr>";
                    foreach($_POST['check_list'] as $selected){
                        echo"<tr><td>".$selected."</td><td><input type=number name=valor_site[]></td></tr>";
                        $_SESSION['lista_public[]']=$selected;

                    }

                    echo"<tr><td><input type='submit' name='submit_valor' value='Submit' /></td></tr>";
                }
            }
if(isset($_POST['submit_valor'])){
                if(!empty($_POST['valor_site'])){
                    foreach($_POST['valor_site'] as $valor_site){
                        echo $selected." tem valor ".$valor_site;
                    } 
                }
            }

2 个答案:

答案 0 :(得分:0)

问题在于这一行:

$_SESSION['lista_public[]']=$selected;

每次都会覆盖$_SESSION['lista_public[]']中存储的值。我建议的是:

$_SESSION['lista_public'] = array();
if(isset($_POST['publicar'])){//to run PHP script on submit
    if(!empty($_POST['check_list'])){
        echo "<tr><td>Sites a Publicar</td><td>Valor</td></tr>";
        foreach($_POST['check_list'] as $selected){
            echo"<tr><td>".$selected."</td><td><input type=number name=valor_site[]></td></tr>";
            $_SESSION['lista_public'][] = $selected;
        }

        echo"<tr><td><input type='submit' name='submit_valor' value='Submit' /></td></tr>";
    }
}

if(isset($_POST['submit_valor'])){
    if(!empty($_POST['valor_site'])){
        $i = 0;
        foreach($_POST['valor_site'] as $valor_site){
            echo $_SESSION['lista_public'][$i++]." tem valor ".$valor_site;
        } 
    }
}

答案 1 :(得分:0)

使用数组

    $temp = array()
    if(isset($_POST['publicar'])){//to run PHP script on submit
            if(!empty($_POST['check_list'])){
                echo "<tr><td>Sites a Publicar</td><td>Valor</td></tr>";
                foreach($_POST['check_list'] as $selected){
                    echo"<tr><td>".$selected."</td><td><input type=number name=valor_site[]></td></tr>";
                    $temp[]=$selected;

                }
                $_SESSION['lista_public'] = $temp;
                echo"<tr><td><input type='submit' name='submit_valor' value='Submit' /></td></tr>";
            }
        }
    if(isset($_POST['submit_valor'])){
    if(!empty($_POST['valor_site'])){
    $i = 0;
    $temp = $_SESSION['lista_public'];
    foreach($_POST['valor_site'] as $valor_site){
        echo $temp[$i++]." tem valor ".$valor_site;
    } 
}