The Concatenation Operator:
• The concatenation operator (.) is used to put two strings together like (+) is used in java 4 concatenation.
• Consider the code:
<?php
$txt1=”Hello World!”;
$txt2=”What a nice day!”;
echo $txt1.” ”.$txt2;
?>
Display:
Hello World! What a nice day!
• If we look at the code above you see that we used the concatenation operator two times. This is because we had to insert a third string (a space character), to separate the two strings.
PHP Form Handling:
• U all r familiar with form tag used in html. Let us see an html form having two input fields and one submit button.
<html>
<body>
<form action="welcome.php" method="post">
Name: <input type="text" name="fname" >
Age: <input type="text" name="age" >
<input type="submit" value=”SUBMIT”>
</form>
</body>
</html>
• In the form tag there r two attributes action and method. The action attribute points to the url where the form is send to, in your case your php script. This script is opened with the entered data so the browser redirects to the php script and there are two methods to transfer-one is GET method and another one is POST method.
• Difference between both the methods is that in GET method, all variable names and values are displayed in the URL and has limits on amount of information to send. So this method should not be used when sending passwords or other sensitive information whereas information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send.
• To access the form data in php you must give the form fields in your html code a name with the name attribute. Inside your php script the form data are saved in the superglobal arrays $_GET or $_POST, depending on which method is used. The index of the array field is the same as the name in the form field, the value is filled from the given form field.
• So When a user fills out the form above and click on the submit button, the form data is sent to a PHP file, called "welcome.php".
• welcome.php page looks like this:
<html>
<body>
Welcome <?php echo $_POST["fname"]; ?>!<br >
You are <?php echo $_POST["age"]; ?> years old.
</body>
</html>
• In the above code a function is used i.e. $_POST. The built-in $_POST function is used to collect values from a form sent with method="post". The "welcome.php" file use the $_POST function to collect form data (the names of the form fields will automatically be the keys in the $_POST array). Similarly, the built-in $_GET function is used to collect values from a form sent with method="get".
• So try making forms and try both types of methods. All the best. :)
here r some queries m'am...
ReplyDelete( actually not from me....bt from my brother who is gng for it )
:)
1. Syntax for functions used???....do they too start with $??
2. What if we r using "Button" type instead of"submit" as the input type????
@Rupani-mam hehe....
ReplyDelete1)Hey vaise abhi mjhe functions cover karne h...
but stil to create ur own fnctn:
its syntax is
function functionName()
{
code to be executed;
}
2)A 'button' is just that, a button, to which you can add additional functionality using Javascript. A 'submit' input type has the default functionality of submitting the form it's placed in (though, of course, you can still add additional functionality using Javascript).
ok!!!
ReplyDeletesomwht similar to Javascript ....rite!!!
:)
@Rupani-
ReplyDeleteIn case of submit type input, submit type has some default functionality i.e. it can b used without adding some additional functionality in it. this addtnl functionality can be added using prgrm lang lyk javascript so in php it can be used without javscript.
But in case of buttons, they are of no use if some functionality is not added in them as they dnt have any default functionality just lyk in java. so they cannot be used alone in php. They are used in combination with some lang lyk javascript.
If still any doubt????plzz ask...
ReplyDelete