0

I want to run the javascript code inbetween the PHP ,where there is IF else condition. but the Javascript code is working independent from the IF ELSE condition. before i have filled the Registeration form and submitted it.

i have also taken help from ChatGPT but it is not working.

if (mysqli_stmt_execute($stmt)) {   
        
        ?>

        <script src="Js/success-registered.js"></script>

        <?php
        header("location: login.php");

        exit;
      } else {
        echo "Something went wrong...cannot redirect!";
      }
    }
  • Php runs on the server javascript in the client , thata needs some learning, usually you have a webpage that gets their dara from a ret communication via ajax for wxample, so try to do all code in php and don't mix it – nbk Jul 10 '23 at 08:08
  • Please show us a minimum reproducible code. Also, JS executes on the client side. It won't inside your if condition. It will sure only execute on the browser based on the script tag you printed(if that's what you mean). – nice_dev Jul 10 '23 at 08:08

0 Answers0