douzhan3900 2016-06-27 00:30
浏览 32
已采纳

为什么html输入提交没有分配$ _POST数组值

Please check on the last part of code where input type="submit" name="save_changes_submit". This form not assigning in $_POST. Whats wrong I am doing here? Is there any html mistake I am doing here? How can I achieve $_POST value form this submit?

echo '<form action="" method="post">ID Number:<input type="number" name="id_number" value="number"><br><br><input type="submit" value="Search Product" name="id_number_submit">';

if (isset($_POST['id_number_submit'])) {
    $id_number = $_POST['id_number'];

    $q = mysqli_query($conn, "SELECT * FROM product WHERE id='$id_number'");

    $row = mysqli_fetch_array($q);

    if (empty($row)) {
        echo "Error: Invalid product id";
    }else{

    $product_name = $row['product_name'];
    $product_des = $row['product_des'];
    $product_price = $row['product_price'];


echo '<br><br><input type="number" name="product_price" value="'.$product_price.'">';
echo '<br><br><input type="text" name="product_name" value="'.$product_name.'">';
echo '<br><br><textarea rows="8" cols="100" name="product_des">'.$product_des.'</textarea><br><input type="submit" value="Save Changes" name="save_changes_submit">';

if (isset($_POST['save_changes_submit'])) {
    echo $c_product_price = $_POST['product_price'];
    echo $c_product_name = $_POST['product_name'];
    echo $c_product_des = $_POST['product_des'];
}
}
}

echo '</form>';

展开全部

  • 写回答

3条回答 默认 最新

  • dongranding3909 2016-06-27 00:52
    关注

    The if condition if(isset($_POST['save_changes_submit'])) was inside if(isset($_POST['id_number_submit'])). And that was the problem. Here it is.

    <?php
    echo '<form action="" method="post">ID Number:<input type="number" name="id_number" value="number"><br><br><input type="submit" value="Search Product" name="id_number_submit">';
    
        if(isset($_POST['id_number_submit'])) {
            $id_number = $_POST['id_number'];
    
            $q = mysqli_query($conn, "SELECT * FROM product WHERE id='$id_number'");
    
            $row = mysqli_fetch_array($q);
    
            if (empty($row)){
                echo "Error: Invalid product id";
            }else{
                $product_name = $row['product_name'];
                $product_des = $row['product_des'];
                $product_price = $row['product_price'];
    
    
            echo '<br><br><input type="number" name="product_price" value="'.$product_price.'">';
            echo '<br><br><input type="text" name="product_name" value="'.$product_name.'">';
            echo '<br><br><textarea rows="8" cols="100" name="product_des">'.$product_des.'</textarea><br><input type="submit" value="Save Changes" name="save_changes_submit">';
            }
        }
        if(isset($_POST['save_changes_submit'])) {
            echo $c_product_price = $_POST['product_price'];
            echo $c_product_name = $_POST['product_name'];
            echo $c_product_des = $_POST['product_des'];
        }
        echo '</form>';
    ?>
    

    展开全部

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部