Click here to Skip to main content
15,879,068 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
<?php

if(isset($_POST['send']))
  {
  if (isset($_SESSION['username']))
  $fp = fopen('messages.txt', 'a',1);
  $message=htmlspecialchars($_POST['message-text']);

  fwrite($fp, "$_SESSION[username]: $message ".PHP_EOL);
        echo "<script>if ( window.history.replaceState ) {
  window.history.replaceState( null, null, window.location.href );
}
document.location.reload()</script>";
  }
}
?> 
can someone make so that if $message is empty it will go to file called stop_talking.html


What I have tried:

i tried asking others and codes like
<?php
if (isset($_POST['send']))
{
if (empty($message))
{
    header('Location: stop_talking.html');
}
else if (isset($_SESSION['username']))
{
    $fp = fopen('messages.txt', 'a', 1);
    $message = htmlspecialchars($_POST['message-text']);
    fwrite($fp, "$_SESSION[username]: $message " . PHP_EOL);
    echo "<script>if ( window.history.replaceState ) {
window.history.replaceState( null, null, window.location.href );
}
document.location.reload()</script>";
};
};
?>
but they didn't work idk why even though I made it myself
Posted
Updated 5-Feb-22 0:50am

 
Share this answer
 
Your code is badly formed again:
PHP
<?php
if (isset($_POST['send']))
{
    if (empty($message))
    {
        header('Location: stop_talking.html');
    }
    else if (isset($_SESSION['username']))
    {
        $fp = fopen('messages.txt', 'a', 1);
        $message = htmlspecialchars($_POST['message-text']);
        fwrite($fp, "$_SESSION[username]: $message " . PHP_EOL);
        echo "<script>if ( window.history.replaceState ) {
            window.history.replaceState( null, null, window.location.href );
        }
        document.location.reload()</script>";
    }; <--- Do not put semi-colons on close braces
}; <--- ditto
?>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900