简体   繁体   English

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

[英]TWO Insert updates in one webpage issues

I have two insert updates on my webpage, i have done this in the past without any issue, however, today i am having major issues, the first insert update works perfectly, but the second doesn't (on pressing the submit button nothing appears in the db table) even through the exactly the same script is being used. 我的网页上有两次插入更新,我过去做的没有任何问题,但是,今天,我遇到了重大问题,第一个插入更新工作正常,但是第二个没有更新(按提交按钮时,什么也没有出现在db表中),即使使用的脚本完全相同。

I am not sure if its the two insert updates in one webpage, or if it is the fact that i need to close the db after the first insert update, which i haven't. 我不确定它是否在一个网页中进行两次插入更新,或者是否是我在第一次插入更新后需要关闭数据库的事实,而我没有。

The db table i am trying to insert into has a unique key, i am also connected to my db or a complete different problem all together. 我要插入的数据库表具有唯一键,我也连接到数据库或一个完全不同的问题。 Extremely frustrated. 极度沮丧。 Please help 请帮忙

The second insert update 第二次插入更新

   $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 的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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM