tHud Posted October 20, 2009 Share Posted October 20, 2009 Hello, I want to use this snippet to make sure the fields in a form are ok before processing it. <FORM method="post"> To:<br> <input type="text" name="name" size="40" value="<?php if($name) { print $name; } else { print "Insert Name"; } ?>"> <input name="action" type="submit" value="Update Form"> </FORM> It works, but I don't understand why. The if statement is checking for the variable $name, but I haven't used the code that I would normally use. What I see in all my tutorials would lead me to use... $name= $_POST['name]; So, I'm confused as to where the $name variable is being found. Thanks for your patience Link to comment https://forums.phpfreaks.com/topic/178324-solved-most-basic-form-question-ever/ Share on other sites More sharing options...
trq Posted October 20, 2009 Share Posted October 20, 2009 Seems your server is poorly configured and has register_globals switched on. This is never a good idea. Link to comment https://forums.phpfreaks.com/topic/178324-solved-most-basic-form-question-ever/#findComment-940280 Share on other sites More sharing options...
tHud Posted October 20, 2009 Author Share Posted October 20, 2009 ah ok - well actually that is good news. So a badly configured server/or register_globals converts the form field name into $name ? Phew, I spent hours last night trying to work that out. Thanks very much for answering so quickly Link to comment https://forums.phpfreaks.com/topic/178324-solved-most-basic-form-question-ever/#findComment-940281 Share on other sites More sharing options...
Alt_F4 Posted October 20, 2009 Share Posted October 20, 2009 this works because as thorpe said Seems your server is poorly configured and has register_globals switched on. This is never a good idea. and therefore the if is checking whether the variable $name exists. As the variable has not been initialized/declared in the code snippet provided the result will be that the textbox will have "Insert Name" in it. if you wanted to use this to display the name after submitting the form, then you are correct and you would need to add $name= $_POST['name]; hope that makes sense Link to comment https://forums.phpfreaks.com/topic/178324-solved-most-basic-form-question-ever/#findComment-940283 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.