How to unsert JavaScript code in php

Hello,

I want to give a registering new user a message when the registration was successful.

When I test the registration process. I add new users but I don’t get the alert message.

Why?

Here is the code

 $result = add_user($firstname, $lastname, $email, $username, $passwordHash);
				 
				if($result == false)
				{
					header('Location: ../signup.php?signup=Could_not_insert_new_USER!');
				} else
				{
					header('Location: ../index.php?signup=success');
					///  Alert a success message
					?>
				  <script type="text/javascript">
				  <!--
					alert('Congratulations you are registered to Trade Explorer');
				  //-->
				  </script>
			    <?php
					exit();

Once the header() statement is executed, anything following that will be ignored. You’ll need to put the welcome in your index page. You can use just HTML for that. A JS alert() is a bit naff.

Your exit statements should go directly after the header() statements.

1 Like

Also, in the posted code, the alert() is commented out.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.