Jump to content

Validation Help


hoponhiggo

Recommended Posts

Hello

 

Im still really new to PHP and im trying to use some form validation for the first time.

 

i have just added

 

f(isset($_POST['username'])){
if($_POST['username'] == ""){
//username empty
die("You must enter a username");
}
} else {
//username not set
} 

 

to my script to ensure a registering user supplies a username. This works ok, exept that it prints the error message in a new blank page.

 

How can i adjust this so that the error message is printed next to the blank field in the existing page?

Link to comment
https://forums.phpfreaks.com/topic/242846-validation-help/
Share on other sites

 

you can join both conditions so that you only have 1 IF statement

die() will completely stop your script. maybe you just need to echo the error, or redirect back to another page?

 

if(isset($_POST['username']) && $_POST['username'] != ''){
   // ok to proceed
} else {
   echo "You must enter a username";
}

 

 

hope this helps

Link to comment
https://forums.phpfreaks.com/topic/242846-validation-help/#findComment-1247310
Share on other sites

yes you can do that one way is to have the register or the login code in one page with the form and do the $_SERVER['PHP_SELF'] (if you don't have it on same page) instead of grabing user info from the html form from another page... And do a simple if condition. if condition not met (in your case no username supply) show the form again. get it? give me full code i can tweak it for ya... hahaha

 

Link to comment
https://forums.phpfreaks.com/topic/242846-validation-help/#findComment-1247576
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.