Php input field validations ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Php input field validations ?

I created a form and linked it to the database using php ... In the form i created 3 inputfields ... And i wrote code if the input field is empty and when i click submit it will show the msg that you must enter the value ...if i enter something in one field and i click submit it is clearing the inputfield where i entered the data ...what should i need to do to keep the entered data and remaining inputfields to show their error message

31st Jan 2018, 6:45 PM
Tarak Yasaswi
Tarak Yasaswi - avatar
6 Answers
+ 2
@toni it's not working 😕
1st Feb 2018, 3:21 AM
Tarak Yasaswi
Tarak Yasaswi - avatar
+ 1
@toni i made it as ... if (isset($_POST['name']){ $name = $_POST['name']; } and <input type="text" name ="name" value = "<?php echo $name ; ?>" > it worked .... Thank You So much 😊😊
1st Feb 2018, 11:45 AM
Tarak Yasaswi
Tarak Yasaswi - avatar
0
basically u have to store those data in session for a moment
31st Jan 2018, 7:06 PM
fahim
0
Do you get an error if you submit the form and the name input is empty? If so declare empty $name variable outside your if statement
1st Feb 2018, 12:28 PM
Toni Isotalo
Toni Isotalo - avatar
- 1
make empty public variables for your inputs $name = ””; make if statement (click function) for your submit button if($_POST[”button”]) { //if inputs are not empty store the value into the correct variable $name = $_POST[”name”]; } Put the php variable into your input value <input type=”text” name=”name” value=”<?php echo $name; ?>” />
31st Jan 2018, 11:23 PM
Toni Isotalo
Toni Isotalo - avatar
- 1
@Tarak it should
1st Feb 2018, 6:02 AM
Toni Isotalo
Toni Isotalo - avatar