Redirect after waiting for PDO fetch to finish

Question

I'm trying to read the database to get value,then update the $_SESSION variable then redirect.

But I think the redirect function is called before the price and notes are updated somehow, because when I get to redirected page, those values are both null.

if (isset($_GET["secret_id"])) {
    $servername = "localhost";
    $username = "user";
    $password = "pass";

    $secret_id = $_GET["secret_id"];

    try {
        $conn = new PDO("mysql:host=$servername;dbname=scotchbox", $username, $password);
        // set the PDO error mode to exception
        $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

        $sql = "SELECT notes, price FROM mt_custom_orders WHERE secret_id = :secret_id;";

        $stmt = $conn->prepare($sql);

        $stmt->bindParam(':secret_id', $secret_id, PDO::PARAM_STR);
        $stmt->execute();
        $row = $stmt->fetch(PDO::FETCH_ASSOC);

        $_SESSION["kr_merchant_id"] = "7";
        $_SESSION["kr_merchant_user_session"] = Yii::app()->functions->generateRandomKey().md5($_SERVER['REMOTE_ADDR']);

        $items = array();
        $item["currentController"] = "store";
        $item["merchant_id"] = "7";
        $item["item_id"] = "5";
        $item["price"] = $row["price"];
        $item["qty"] = "1";
        $item["discount"] = "";
        $item["notes"] = $row["notes"];
        $item["row"] = "";
        $item["two_flavors"] = "";
        $item["non_taxable"] = "1";
        $item["sub_item"] = "";

        $items[] = $item;

        $_SESSION["kr_item"] = $items;

        redirect();

    }
    catch(PDOException $e)
    {
        echo "Connection failed: " . $e->getMessage();
    }

}

I am using the Yii framework if that makes any difference.


Show source
| pdo   | php   | mysql   | redirect   | yii   2017-01-07 18:01 0 Answers

Answers to Redirect after waiting for PDO fetch to finish ( 0 )

Leave a reply to - Redirect after waiting for PDO fetch to finish

◀ Go back