bolaowoade Posted December 25, 2010 Share Posted December 25, 2010 Hi guys i am a PHP newbie trying to learn from the beginning. I am reading a php book and i can't get past a particular example because $_GET and $_POST just won't work. Below is the code i am working with: HTML File <form action="welcome1.php" method="get"> <div> <label for="firstname">First name: <input type="text" name"firstname" id="firstname"/></label> </div> <div> <label for="lastname"> Last name: <input type="text" name="lastname" id="lastname"/> </label> </div> <div> <input type="submit" value="GO" /> </div> PHP file <?php $firstname = $_GET['firstname']; $lastname = $_GET['lastname']; print 'Welcome to our website, ' . htmlspecialchars($firstname, ENT_QUOTES, 'UTF-8') . ' ' . htmlspecialchars($lastname, ENT_QUOTES, 'UTF-8') . '!'; ?> I am working on a windows pc with Vista home edition installed. I run a localhost server installed via XAMMP. Please this has been a recurring problem for me. Each time i get to this stage in the past i always get stuck. $_GET and $_POST just does not work for me. Please heeeelp! Quote Link to comment https://forums.phpfreaks.com/topic/222605-using-_get-and-_post/ Share on other sites More sharing options...
the182guy Posted December 25, 2010 Share Posted December 25, 2010 There is an error on this line <label for="firstname">First name: <input type="text" name"firstname" You're missing an = betweeen name and "firstname" Quote Link to comment https://forums.phpfreaks.com/topic/222605-using-_get-and-_post/#findComment-1151222 Share on other sites More sharing options...
bolaowoade Posted December 25, 2010 Author Share Posted December 25, 2010 Thanks 182guy, i've corrected the error and tried it again but it still does not work. Do you think it could be soemthing with my php setting because i have encountered this problem in hte past and it always discourages me from continuing to learn phe. Quote Link to comment https://forums.phpfreaks.com/topic/222605-using-_get-and-_post/#findComment-1151223 Share on other sites More sharing options...
noXstyle Posted December 25, 2010 Share Posted December 25, 2010 XAMMP? ... if you run windows as you said it would be wamp at that point ... anyway tested your code, works perfectly... how did you install your wamp server? is your php working at all? can you attach your phpinfo(); for further info? Quote Link to comment https://forums.phpfreaks.com/topic/222605-using-_get-and-_post/#findComment-1151235 Share on other sites More sharing options...
Pikachu2000 Posted December 25, 2010 Share Posted December 25, 2010 It could still be XAMPP since that is available for Win. Anyhow, you don't have a closing </form> tag in that code. Quote Link to comment https://forums.phpfreaks.com/topic/222605-using-_get-and-_post/#findComment-1151251 Share on other sites More sharing options...
momasri Posted December 25, 2010 Share Posted December 25, 2010 Can you try this PHP code: <?php $firstname = $_GET['firstname']; $lastname = $_GET['lastname']; echo 'Welcome to our website' . $$firstname . " " . $lastname; ?> Quote Link to comment https://forums.phpfreaks.com/topic/222605-using-_get-and-_post/#findComment-1151253 Share on other sites More sharing options...
Pikachu2000 Posted December 25, 2010 Share Posted December 25, 2010 Your <label> tags should also be closed before opening the <input> tags. Try this: <form action="welcome1.php" method="get"> <div> <label for="firstname">First name: </label><input type="text" name="firstname" id="firstname" /> </div> <div> <label for="lastname">Last name: </label><input type="text" name="lastname" id="lastname" /> </div> <div> <input type="submit" value="GO" /> </div> </form> Then, if it still doesn't function as expected, put this immediately after the opening <?php tag in welcome1.php to see exactly what is in the $_GET array. echo '<pre>'; print_r($_GET); echo '<pre>'; [/code] Quote Link to comment https://forums.phpfreaks.com/topic/222605-using-_get-and-_post/#findComment-1151257 Share on other sites More sharing options...
noXstyle Posted December 25, 2010 Share Posted December 25, 2010 Thanks pica, i didnt know people would be so stupid to port mac soft on windows even tho native version is available.. and </form> closing tag didnt really matter to code functionality... its just malformed. (and same applies to label and input tags) and what comes to your new code: works just fine when the double dollar sign is replaced by just one. (as it should ) Quote Link to comment https://forums.phpfreaks.com/topic/222605-using-_get-and-_post/#findComment-1151258 Share on other sites More sharing options...
bolaowoade Posted December 25, 2010 Author Share Posted December 25, 2010 Thanks guys. I've uninstalled XAMMP and installed Wampserver and when i run the code through localhost it works. So the problem was with XAMMP's set up somewhere. Now back to learning PHP. I'm sure i will be needing your help again. ;) Quote Link to comment https://forums.phpfreaks.com/topic/222605-using-_get-and-_post/#findComment-1151343 Share on other sites More sharing options...
momasri Posted December 26, 2010 Share Posted December 26, 2010 booooooooooooo Quote Link to comment https://forums.phpfreaks.com/topic/222605-using-_get-and-_post/#findComment-1151457 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.