douzhan3900 2016-06-27 08: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 08: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条)

报告相同问题?

悬赏问题

  • ¥15 preLaunchTask"C/C++: aarch64- apple-darwin22-g++-14 生成活动 文件”已终止,退出代码为-1。
  • ¥18 关于#贝叶斯概率#的问题:这篇文章中利用em算法求出了对数似然值作为概率表参数,然后进行概率表计算,这个概率表是怎样计算的呀
  • ¥20 C#上传XML格式数据
  • ¥15 elementui上传结合oss接口断点续传,现在只差停止上传和继续上传,各大精英看下
  • ¥100 单片机hardfaulr
  • ¥20 手机截图相片分辨率降低一半
  • ¥50 求一段sql语句,遇到小难题了,可以50米解决
  • ¥15 速求,对多种商品的购买力优化问题(用遗传算法、枚举法、粒子群算法、模拟退火算法等方法求解)
  • ¥100 速求!商品购买力最优化问题(用遗传算法求解,给出python代码)
  • ¥15 虚拟机检测,可以是封装好的DLL,可付费