TWO在一个网页中插入更新问题


TWO Insert updates in one webpage issues

我的网页上有两次插入更新,我过去做过,没有任何问题,然而,今天我遇到了重大问题,第一次插入更新效果很好,但第二次没有(按下提交按钮时,数据库表中没有显示任何内容),即使使用了完全相同的脚本。

我不确定是一个网页中的两次插入更新,还是在第一次插入更新后我需要关闭数据库,但我没有。

我试图插入的数据库表有一个唯一的密钥,我也连接到了我的数据库或一个完全不同的问题。极度沮丧。请帮助

第二次插入更新

   $Restaurant_id = mysqli_real_escape_string($dbc, $_GET['restaurant_id']);
                 if (isset($_POST['Save_changes'])) {
        $code = $_POST['Pcode'];

        $insert_ = "INSERT INTO Delivery_Pcode
  (Pcode,Restaurant_ID) VALUES(?,?)
   ON DUPLICATE KEY 
    UPDATE 
    Pcode  = ?
    ,Restaurant_ID  = ?";

        $r_query = mysqli_prepare($dbc, $insert_);
        //new
        // $stmt = mysqli_prepare($dbc, $insert_c);
        //debugging
        //$run_query = $dbc->prepare($insert_Delex);
        $r_query->bind_param('sisi', $code,$Restaurant_id,$code,$Restaurant_id);
        // THIS now executes the above transaction, returns TRUE if successful - issdissd duplicate update
        if (!$r_query->execute()) {
            $insertEr = "There was an error inserting data: " . $r_query->error;
        }
        print "affeted rows:" . $r_query->affected_rows; //how many records affected? 
        $r_query->free_result(); // Frees memory on completion 
        $r_query->close(); //closes this action 
    }

HTML

  <form id="delivery_pcodes" action ="Franchise_postcodes.php?restaurant_id=<?php echo $_GET['restaurant_id'] ?>&Franchise=<?php echo $_GET['Franchise']; ?>" method="POST">
            <input type="text" name="pcode" id="pcode"  value="<?php echo $pcodes; ?>"  placeholder="e.g LS1,LS2,LS3" tabindex="2">
            <input type="number" name="pcode_price" id="pcode_price"  value=""  placeholder="e.g 3.50" tabindex="2">
            <button type="submit" id="Save_changes" name="Save_changes" value="Save Changes">
                <span class="glyphicon glyphicon-ok"></span> Save changes
            </button>
        </form>

在这段代码中,您将执行$code,$Restaurant_id两次。

 $r_query->bind_param('sisi', $code,$Restaurant_id,$code,$Restaurant_id);