Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

340
Vistas
After alert it will stay on the same page

I need help on my sign up page. I made an alert for the users to see that all the fields are required . My problem is every time I click OK on the alert it redirects to signupMysql.php which is a blank page. Want I want is for it to stay on signup.php as long as some as the fields are not complete.

I think the action has something to do with my problem.

Here is my signup.php

<form class="register-form" action="signupMysql.php" method="post">
  <p class="message">Don't have an account?</p>
  <input type="text" placeholder="Username" name="username">
  <input type="text" placeholder="Last Name" name="lastname">
  <input type="text" placeholder="First Name" name="firstname">
  <input type="text" placeholder="Contact Number" name="contactnum">
  <input type="text" placeholder="Email address" name="email">
  <input type="password" placeholder="Password" name="password">
  <input type="password" placeholder="Re-enter Password" name="repassword">
  <input type="Submit" value="Sign Up">

</form>

some of the codes of my signupMysql.php

if (empty($username) || empty ($lastname) || empty($firstname) || 
empty($contactnumber) || empty($email) 
|| empty ($password) || empty ($repassword)){

$message = "Fill all fields";
echo "<script type='text/javascript'>alert('$message');</script>";


}

I hope someone could help me. Thank you so much in advance.

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

In the forms, try to add the required attribute. For example;

<input type="text" placeholder="Username" name="username" required/>

This will prevent users from submitting empty values.

Also, alert() will not stop them as it just displays information and does not do anything else

over 4 years ago · Santiago Trujillo Denunciar

0

Please add one more statement after echo in signupMysql.php

header("location:signup.php");

If you strictly want the validation to be done through PHP then you can use this code. Also if you want it to be done before the form is actually submitted you can use the code given by Douglas Hosea.

Hope it helps! All the best!

over 4 years ago · Santiago Trujillo Denunciar

0

Your problem is that your form is submitting and you are being taken to the next page where you have your validation. If you don't want the user to leave the page when the form is not complete, you will need some form validation in the browser using JavaScript and/or HTML5.

You can stop the form from submitting using JavaScript: How to prevent form from being submitted?

Or you can look into HTML5 form validation and the "required" attribute: Required attribute HTML5 https://www.w3schools.com/tags/att_input_required.asp

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda