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条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器