duanshan188866 2019-02-27 17:53
浏览 65
已采纳

如果Oracle插入成功并失败,则重定向为PHP

I'm wanting to setup Bootstrap alerts for successful and unsuccessful inserts. I've had a look around and couldn't find any examples of people having 2 redirects one for a successful insert and one for a failed insert.

 if(isset($_POST['CountryID'])) {

            $CountryID = $_POST['CountryID'];
            if(isset($_POST['CountryName'])) {
                $CountryName = $_POST['CountryName'];
            }
            if(isset($_POST['GPD'])){
                $GDP = $_POST['GPD'];
            }

            $stmt = oci_parse($conn, "INSERT INTO COUNTRY (COUNTRYNAME, GDP) VALUES (:CountryName, :GDP) WHERE COUNTRYID = :CountryID");

            ocibindbyname($stmt, ":CountryID", $CountryID);
            oci_bind_by_name($stmt, ":CountryName", $CountryName);
            oci_bind_by_name($stmt, ":GDP", $GDP);

            oci_execute($stmt);
            oci_commit($conn);
            oci_free_statement($stmt);

//insert if successful here
            header("Location: ../index.php?Success=Country has been updated!");
//insert else here
            header("Location: ../index.php?Danger=Country update failed!");

    }
  • 写回答

2条回答 默认 最新

  • 普通网友 2019-02-28 17:24
    关注
    oci_execute($stmt);
    $Affected = oci_num_rows($stmt);
    oci_commit($conn);
    
    
    // echo $Gross;
    // echo $CountryName;
    if(count($Affected) > 0){
        header("Location: ../index.php?Success=$CountryName has been created!");
    } else {
        header("Location: ../index.php?Danger=Country hasn't been created!");
    }
    
    oci_free_statement($stmt);
    oci_close($conn);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?