1

I currently have 3 pages: index.php, Insertred.php andhomered.php

Homered is a form that updates to the database after submission and Index.php is a page that shows the results. I've done some searching about auto refreshing page but all of them are timer refresh.

Is it possible to make index.php automatically refresh on homered.php submission? Currently it does this: homered.php submit button > insertred.php > index.php

homered.php: (removed the php part as its just session checks)

<html>

<head>
    <link rel="stylesheet" type="text/css" href="homered.css">                           
    </head>
<body>
<div class="centerimage">
<img src="images/anonymousfacepng.png" alt="Avatar" align="middle">
</div>
<div class="home-page">  
  <div class="form">
    <form class="home-form" action="insertred.php" method="post">
    <input type="text" placeholder="FTP Password" name="FTPBreach"/>
    <input type="text" placeholder="XP2 Victim IP" name="VictimIP"/>
    <input type="text" placeholder="XP2 Victim Password" name="VictimPass"/>
    <input type="text" placeholder="SQL Username" name="SQLUser"/>
    <input type="text" placeholder="SQL Password" name="SQLPass"/>
    <button>Submit</button>
      <p class="message"><a href="logoutred.php">logout</a></p>
    </form>
  </div>
</div>
</body>
<footer>
    © 
</footer>
</html>

Insertred.php:

    <?php
    $db = mysqli_connect('prjtest1', 'root', 'test', '165619z_database');
    if (!$db)
    {
        die('Could not connect: ' . mysql_error());
    }
    $currenttime = date('Y-m-d H:i:s');
    echo $sql="UPDATE indextableredupdated SET FTPBreach = '$_POST[FTPBreach]', VictimIP = '$_POST[VictimIP]', VictimPass = '$_POST[VictimPass]', SQLUser = '$_POST[SQLUser]', SQLPass = '$_POST[SQLPass]', message = '$_POST[message]', time = '$currenttime' WHERE user = '2'" ;

    $query = mysqli_query($db,$sql);

    if (!mysqli_query($db, $sql))
    {
        die('Error: ' . mysql_error());
    }

    if($query)
    {

    header("location: index.php");
    }
    ?>

Not sure if you need the codes for index.php as it's quite long. TLDR; i need index.php to refresh only after insertred.php

Chris
  • 426
  • 2
  • 7
  • 18
Coln
  • 29
  • 6

1 Answers1

0

This is actually not possible. PHP is a server side language and is only executed once when its requested. Making a listener or similar is not possible due to how PHP compiles.
It executes once, and perhaps echo's any data etc. But as the page is viewed to the client, no server side code will be ran until the page is refreshed once again.

Click here to watch a video teaching you about how PHP works in the background/on the server

Chris
  • 426
  • 2
  • 7
  • 18
  • Hi, is there anyway i could refresh the data retrieved from database every X seconds instead of refreshing the page? – Coln Dec 10 '18 at 09:12
  • Sorry for late response, I am in class right now. https://stackoverflow.com/questions/11497611/php-auto-refreshing-page – Chris Dec 10 '18 at 10:08