your variable has to be set befor you go to that if-clause.
in your case you want to check if the variable is true and if so it should alert() with the content Form submitted successfully.
there are 2 ways to set a variable.
- define a constant with the define("success", true)- function. Then you can let your code as it is.
- or define a variable lik $success = true;
then you have to change your code to this:
<?php 
$success = true; // define the variable and set it to true
if ($success) {
    echo "<script type=\"text/javascript\">" .
        "alert('Form submitted successfully.');" .
        "</script>";
} 
?>
or
<?php
$success = true; // define the variable and set it to true
if (isset($success) && !empty($success) && $success != false) {
    echo "<script type=\"text/javascript\">" .
        "alert('Form submitted successfully.');" .
        "</script>";
}
?>