Popular Posts

Friday, 2 July 2010

Form processing in PHP

Form processing in PHP

kindly visit www.apepoint.com for the original content of this blog


Before moving to this chapter i must suggest you to go through the basis form designing tutorial of HTML here i am giving you an example of a simple form which let revise your HTML concept.



<br />Say Hellow <br />



Kindly proivde us your E-mail ID













You can understand that the form HTML code let user to enter his email ID and submit to process for saving in our database. You also noticed that for form action i passed emailsave.php file and method is "get". It means emailsave.php will process the form and by using GET it will fetch the values and save in our database.

Here is a code of emailsave.php


$mail=$_GET['mail']; // here by this form field is saved in variable and now we can //process

// now we will write code to save in our database

mysql_connect("localhost","username","password") ;

mysql_select_db("test");
mysql_query("insert into request values(email)");

mysql_close();

echo " Email saved in our data base";

?>

In the above code you noticed by that by using $_GET[' '] the value of form field was picked and by 5 lines of mysql code email was saved in our database. in case you have not studied these code I recommend to study at http://www.apepoint.com/php_mysql.php


You may ask if we take POST as form method in file emailrequest.html then what changes we require in file emailsave.php In this case we need a small change i case of $_GET we will require $_POST[' '] and the remaining code will remain unchanged

see what about cases when we forget to recall about the form action wether it was get or post then no issue we may use $_REQUEST you must be happy to know that $_REQUEST can be used

One more thing you must notice that by using $_GET the alue which user enter in the form get saved in variable $mail . In the eamilsave.php we write code to save in database but we can use this variable for any other purpose

I must write here that in above example i show how user let to provide his email but in real it require some more effort. this effort is called validation you need to write script to validate this form in 3 different stage one by using JavaScript or Jquery and by PHP and mysql

Very soon some more example will be uploaded for this and this will help you understand more and more.

No comments:

Post a Comment