为什么UPDATE会创建新记录?

For event listing page. After inserting record into db I capture last ID with

//Store ID[LAST]
    $ID = mysqli_insert_id($db);

Next the page shows event formatted for easy reading. Then user can hold or approve item for publication with 2 buttons: Draft, Publish. I use submits buttons for each:

//Check ID value (use for testing)
    echo "<p>ID = ".$ID."</p>
";

    echo "<form action='".$_SERVER['PHP_SELF']."' method='GET'>
    <input type='submit' name='submitDraft' value='Draft' />
    <input type='submit' name='submitPublish' value='Publish' />
    </form>";

Now I use conditional to update record according to button chosen. (Note connect.php is include that manages passcodes and connection statement.)

if (isset($_REQUEST["submitDraft"])) {
    include('includes/connect.php');
    $sql="UPDATE sessions SET postit='0' WHERE ID='$ID'";
    if (mysqli_query($db, $sql)) {
            echo "Record updated successfully";
        } else {
            echo "Error updating record: " . mysqli_error($db);
        }

        mysqli_close($db);
    }

    if (isset($_REQUEST["submitPublish"])) {
    include('includes/connect.php');
    $sql="UPDATE sessions SET postit='1' WHERE ID='$ID'";
    if (mysqli_query($db, $sql)) {
            echo "Record updated successfully";
        } else {
            echo "Error updating record: " . mysqli_error($db);
        }

        mysqli_close($db);
    }

My problem is UPDATE statement adds new record to table but should update same record. What is my mistake please.

查看全部
duancifu6769
duancifu6769
2016/08/13 02:59
  • submit
  • record
  • php
  • mysql
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

2个回复