Hi everyone
I am facing a little issue please help me in this regards
I have created a form with validation all the validation fields are working fine but in the end i am facing that after validating all the fields should be insert into database but for the test i have just placed to display sucess message but its reloading the form but i want if every thing is fine it should create a session first then submit all values into database and then redirect to the sucess page and display the submitted values with thanks message. i search over the internet but nothing works for me please help me in this here is my code

if((strlen($valid_name)>0) && (strlen($valid_email)>0) && strlen($valid_gender>0) && strlen($dob>0) && strlen(valid_weight>0) && strlen(valid_height>0) && strlen($valid_bloodgrpsection>0) && strlen($valid_phonenum>0) && strlen($valid_mobilenum>0 ) && strlen($valid_address>0) && strlen($valid_country>0) && strlen($valid_state>0) && strlen($valid_city>0) && strlen(valid_privacysec>0))
{
echo "Thanks";

}
else
{

}

That has got to be the longest sentence I have ever seen, and I couldn't unfortunately understand a word of it.

Could you rephrase it please (bullet pointing it might help), stating what problem you are having and what you want it to do. From what I gather, you want it to insert into the DB, create a session and display a message but your current code isn't doing that?

Currently in your code, all you have is an If statement which checks your input against a criteria. If one of those criteria fails then it would go to your Else block which has nothing in it. Otherwise it echos "Thanks".

Your <form> element should have an "action" attribute that tells it which page to load and a "method" attribute to define what kind of request is being done. E.g.

<form action="do_action.php" method="post">

Then, on do_action.php, in this example, you should validate the user's input. If it is not valid, you can save in a session that errors have occurred and redirect the user back to where he came from, and display the errors that you have saved in the session. Then unset the session, so that he won't see the same errors again when he does another form submission.

If the user's input is valid, you could save in a session that everything worked out well. You could then insert his input into your database and redirect him to a page which displays a success message.

Redirection can be done by setting a redirection header. E.g.:

header('Location: my_location.php');

This tells the page to redirect the user to my_location.php when the script finishes executing or reaches a custom exit point. If you want to redirect the user to where he came from, you could set the "Location" to $_SERVER['HTTP_REFERER']. For more info about $_SERVER variables, click here.

Database insertion can be done, for example, by using MySQL functions.

Yes but i know that every thing works fine but check the if statement i know only this statement giving me error please check this statement and check what i did wrong in the if statement with variables

valid_weight, valid_height and valid_privacysec are missing $

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.