how to call variable in next page

Am getting Notice: Undefined index: getdobcval in C:\xampp\htdocs\bgtest\buy_test.php on line 11

Am trying call variable, how to call variable from page1.php to page2.php

am using below form action

<form action="" method="POST">
  <input type="text" name="getdobcval">
  <input type="submit">
</form>

when user click submit value, it'l store the value in database and show the values in same page, i used page redirectory option after function finish (after 5 seconds). page redirectory working but after page am getting error

how to call <input type="text" name="getdobcval"> value ?

this is my database

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

$getdob_cval = $_POST['getdobtcval'];                                               

$conn = mysqli_connect("localhost", "root", "", "bgtest");
$sql = "INSERT INTO bgtest(getdobtcval) VALUES('$getdob_cval')";
if (mysqli_query($conn, $sql)){
    echo "Please wait, We are redirecting another page!";
    echo '<script> setTimeout(function(){
                    window.location.href="buy_test.php"
        },3000);
     </script>';
}else{
    echo "error";
 }      
    mysqli_close($conn);
}

1 answer

  • answered 2017-06-17 18:14 InfiniteStack

    This is usually done via a server-side script. Let's say script.php

    <form action = "script.php"...
    

    Or make sure that

    <form action = ""...
    

    Is specified in from on a .PHP page itself.

    When the script refreshes, the values will be available via following array:

    <?php
        $a = $_POST["getdobcval"];  // Submitted as POST
        $b = $_GET["getdobcval"];    // Submitted as GET
    ?>
    

    Or alternatively you can receive it regardless of how it was submitted by:

    <?php
        $c = $_REQUEST["getdobcval"];
    ?>