Click here to Skip to main content
15,891,864 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dears ,

I am a beginner in PHP , i like it so much ,i try everyday to know a new thing about it .
I have a question and I hope to find an answer .

lets first have a look on the below simple code .

first page : first.php
PHP
<form method="post" action="second.php">
<input type="text" name="fname">
<input type="text" name="lname">
<input type="submit" value="Go">
</form>

second page : second.php -----> version 1
PHP
<?php
$firstname=$_post["fname"];
$lastname=$_post["lname"];
echo $fistname.$lastname;
?>

second page : second.php -----> version 2
PHP
<?php
echo $fname.$lname;
?>

Now , my question is :
What is the difference between version 1 of second page and vesion 2 of second page ??
i try both of them and both of them are work with no problem .
so do they have the same meaning ?
in other words Does $_post mandatory ? or i can ignore it .
Thanks .
Posted
Comments
Sergey Alexandrovich Kryukov 8-May-13 0:38am    
The second case should not work. You probably misspelled on of the names.
What do you mean $_POST mandatory? How can it possible be optional?
—SA
Hercal 8-May-13 1:00am    
Dear sergey ,

please take a look on this video

http://www.free4learn.com/index.php?option=com_content&view=article&id=60:checkbox-a-select-option&catid=3:php&Itemid=7

it is about 7 min , you will understand what i mean and reply me please ASAP . thanks
Sergey Alexandrovich Kryukov 8-May-13 1:04am    
No, thank you. It does not worth wasting 7 minutes. Keep in mind that most members will agree with me and won't want to watch it.
If you have a question, ask it.
—SA
Hercal 8-May-13 1:24am    
As you see in my first line , i wrote that i am a beginner , so may i can't tell you everything i mean in a clear way , it doesn't matter who agree with who ,the most important thing to me is to understand ...not to see all people here agree with me or agree with you ...... you know i totally agree with your opinion but i just need to understand and asking how this example works with him in video ,....any way thanks .
Sergey Alexandrovich Kryukov 8-May-13 1:34am    
I agree with you. By "most members will agree with me" I just wanted to give you a useful advice: as people tend to ignore external downloads, it won't be an effective way to communicate. I sometimes reference just one video here; and people often watch it, but only because I promise it's really funny. :-)
—SA

1 solution

$_post is not mandatory it is rather optional thing.This is due to a setting in your php ini.
Using Register Globals.There are various way to on off it.Making it on is not the best practice.
By using this means $fname to access the value you will be meshed up while handling larger code base.Hope It helps

Thanks
Debasis
 
Share this answer
 
Comments
Hercal 8-May-13 1:45am    
of course it helps , thank u so much , debasis .
debasis behera 8-May-13 5:56am    
Please accept this answer, if it has helped you in any way.
This will help others to find the answer in one go and you will also be awarded with some points for this action...

Thanks,
Debasis
Nice Answer. +5 ed...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900