0

please excuse me for my bad english.

I'm trying to write a website similiar Facebook's chronics. I had testing it on localhost with xampp. There was it fine. After the upload of my documents on my webspace, I get the warning-message. My origin problem is, when I refresh my site the last message (who was save on mysql) will be write and save repeatedly.

Now I'm knowing what my problem is, the order from output and "header('Location: site.php');".

if I put the command before my output, than is the webside refreshing too often.

If I put an "@flush();" before my command, it's don't change something.

If I put an "exit();" after my command, my messages will do not show.

I do not understand, what is so differently between xampp localhost and mysql on webspace.

My code for the php-function to save is:

function saveMessage($mensch){
global $pdo;

$datum = date("Y.m.d",time());
$zeit = date("H:i:s",time());

$nachricht = $_POST['eigeneNachricht'];
$nachricht = preg_replace( '/[^a-z0-9ÄäÖöÜü.,;:-_ ]/i', '', $nachricht );

$speichern = $pdo->prepare("INSERT INTO nachrichtensammlung (Nickname, Datum, Zeit, Nachricht) VALUES (:mensch,:datum2,:zeit,:nachricht)");
$speichern->execute(array('mensch' => "$mensch", 'datum2' => $datum, 'zeit' => $zeit, 'nachricht' => "$nachricht"));

echo "$mensch hat am $datum, um $zeit geschrieben: <br>  \n <b> $nachricht </b> <hr />";

header('Location: downloads.php');
exit();

}

My php-function to show my messages:

function showMessage($mensch){
global $pdo;

$anzahlEintrage = $pdo->prepare("SELECT * FROM nachrichtensammlung WHERE Nickname = '$mensch'");
$anzahlEintrage->execute(array("$mensch"));
$anzahl = $anzahlEintrage->rowCount();

$auslesen = "SELECT * FROM nachrichtensammlung WHERE Nickname = '$mensch'";
$row = $pdo->query($auslesen)->fetch();

$ergebnisse = $pdo->query("SELECT * FROM nachrichtensammlung WHERE Nickname = '$mensch'");

echo "(insgesamt $anzahl Nachrichten) <br > \n";
$i = 1;
while($reihe = $ergebnisse->fetch()){
    echo "<artikel>";
    echo "<avatarKlein> </avatarKlein>";
    echo "<nachricht>";
    echo "<i>[Nachricht $i]</i> Am ";
    echo $reihe['Datum'];
    echo " um ";
    echo $reihe['zeit'];
    echo "schrieb $mensch: <br> \n";
    echo $reihe['Nachricht'];
    echo "<hr /> ";
    echo "</nachricht>";
    echo "</artikel> <hr />";
    $i++;
}

$pdo = null;

}

My php-functions are not in my html-script. It's in a own php-site.

I hope someone has an idea how I can solve my problem.

Who was branding my question like a dublicate? I did find all the other "answers" here, before I wrote my question. No "answer" is helping me.

Maybe I don't see the "answer", then write the answer too. It is impossible, to branding like dublicate, without one or two sentences. I thought in Germany are crazy people only.

WBergmann
  • 1
  • 2
  • Where is the answer? On stackoverflow is no answer for my problem till now – WBergmann Jun 26 '18 at 01:12
  • I found a solution by myself. – WBergmann Jun 26 '18 at 03:57
  • I put the "header("Location: website.php");" with an if-query on top (under "$_SESSION"). And I asking my $_GET-variable if it set. Visit a user at the first time, GET isn't exist. After using a button -> GET is existing -> function is calling -> function works -> side is new loading -> if-query see GET and call new location. No Warnings, it is my solution which works. Maybe has someone a better idea. – WBergmann Jun 26 '18 at 04:07

0 Answers0