1

I need to send post data to another page programatically. I have 2 DateTime in Database I want to compare these DateTimes. and if one of them is bigger than another automatically send post data to another page.

this is simple code:

require('connect.php');
$sql = 'SELECT * FROM POSTS ORDER BY POSTDATETIME ASC';

$result = $conn->query($sql);

if($result->num_rows>0)
{
    while($row=$result->fetch_assoc())
    {
        echo $row["ID"].".".$row["PostDateTime"]."<br/>";
        $text = $row["Text"];

        $d = new DateTime("now");
        $d1 = new DateTime($row["PostDateTime"]);
        if($d>$d1)
            {
                // Send Post Data to another page;

            }
        else
            {
                echo "false<br/>";
            }
    }
}

I googled but there is no way to send automatically post data without any form or ajax . ajax needs to some event occurs. And I don't have any Idea how to do that . I will appreciate any tips.

3 Answers 3

1

You could use CURL to send a post request.

require('connect.php');
$sql = 'SELECT * FROM POSTS ORDER BY POSTDATETIME ASC';

$result = $conn->query($sql);

if($result->num_rows>0)
{
    while($row=$result->fetch_assoc())
    {
        echo $row["ID"].".".$row["PostDateTime"]."<br/>";
        $text = $row["Text"];

        $d = new DateTime("now");
        $d1 = new DateTime($row["PostDateTime"]);
        if($d>$d1)
        {
            $ch = curl_init('http://www.linktoyourotherpage.com');
            curl_setopt($ch, CURLOPT_POSTFIELDS, $row);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            $response = curl_exec($ch);
            curl_close($ch);
        }
        else
        {
            echo "false<br/>";
        }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

0

The only way to achieve what you're doing is with a intermediate page that sends the user to Page C. Here's a small/simple snippet on how you can achieve that:

<?php
 if($d>$d1) { ?>
<form id="myForm" action="Page_C.php" method="post">
<?php
    foreach ($_POST as $a => $b) {
        echo '<input type="hidden" name="'.htmlentities($a).'" value="'.htmlentities($b).'">';
    }
?>
</form>
<script type="text/javascript">
    document.getElementById('myForm').submit();
</script>
<?php } else {
            echo "false<br/>";
      }
  ?>

Comments

0

store the data in a global variable say for example $_SESSION and redirect to another page ... session start and use the global variable.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.