peddel Posted August 5, 2008 Share Posted August 5, 2008 On the moment im working on something for a company. They assigned me a company computer that i could use and configure my wantings. Since i started i have had problems with forms, things i never had problems with before on my own pc! Every time i run the script, it does not react to my php code after submitting the form ! Can someone explain me what can be the problem? Im using Aptana - php environment for making my code. Under here is the simples form i could think of, yet it does not work ! Anyone wanna give me push in right direction? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> </head> <body> <form id="test" method="post"> <input type="text" name="field"></input> <input type="submit" name="button" value="press here"></input> <input type="hidden" name="hidden" value="1"></input> </form> </body> <?php if($_POST[hidden] == 1) { print("U typed : ".$_POST[field]); } ?> </html> Till now this has worked for me, but it can be im making a huge mistake! Hope to get some answers soon Link to comment https://forums.phpfreaks.com/topic/118225-solved-problem-with-php-script/ Share on other sites More sharing options...
bothwell Posted August 5, 2008 Share Posted August 5, 2008 Your form doesn't have an action, maybe? <form id="test" method="post" action=""> Link to comment https://forums.phpfreaks.com/topic/118225-solved-problem-with-php-script/#findComment-608426 Share on other sites More sharing options...
peddel Posted August 5, 2008 Author Share Posted August 5, 2008 Your form doesn't have an action, maybe? <form id="test" method="post" action=""> >___< indeed it doesnt Thing is, it always worked without, by using that hidden variable so i learned it the wrong way i guess What should i add at the action item to make it work? Link to comment https://forums.phpfreaks.com/topic/118225-solved-problem-with-php-script/#findComment-608429 Share on other sites More sharing options...
peddel Posted August 5, 2008 Author Share Posted August 5, 2008 anyone? sorry for the bump Link to comment https://forums.phpfreaks.com/topic/118225-solved-problem-with-php-script/#findComment-608439 Share on other sites More sharing options...
abdfahim Posted August 5, 2008 Share Posted August 5, 2008 put blank, if you have the after action code in the same page (like urs), like <form id="test" method="post" action=""> if you have ur after action code in any other page, just mention that page in action, like <form id="test" method="post" action="actionpage.php"> btw, as far as I know, it works without action as long as you have your "after form submit" code in the same file. Link to comment https://forums.phpfreaks.com/topic/118225-solved-problem-with-php-script/#findComment-608447 Share on other sites More sharing options...
JasonLewis Posted August 5, 2008 Share Posted August 5, 2008 Okay well first up, your HTML is wrong. <input> tags are self closing, so you don't need the </input> Example: <input type="text" name="something" id="something" /> You can make the action for the form tag this: <?php echo $_SERVER['REQUEST_URI']; ?> I don't like to leave it blank. You don't have to use a hidden field either. You can get the value of a submit button $_POST. So because it has a value, when they submit the form it will always have the value. So instead of checking the hidden value to be one you can check: if(isset($_POST['button'])){ That will check to see if the variable is set. One more thing, when refering to array keys, which is the field name. You have done it like this: $_POST[field] You should wrap it in quotes so that PHP doesn't think it is a constant. So it should become this: $_POST['field'] Good luck. Link to comment https://forums.phpfreaks.com/topic/118225-solved-problem-with-php-script/#findComment-608450 Share on other sites More sharing options...
peddel Posted August 5, 2008 Author Share Posted August 5, 2008 I will try those last things and keep u guys updated Link to comment https://forums.phpfreaks.com/topic/118225-solved-problem-with-php-script/#findComment-608451 Share on other sites More sharing options...
abdfahim Posted August 5, 2008 Share Posted August 5, 2008 Hi ProjectFear.. all ur advices are v good for a perfect coding. But the thing is, his code still works in my server, without those ! So, I guess there must be something in server configuration file! Link to comment https://forums.phpfreaks.com/topic/118225-solved-problem-with-php-script/#findComment-608454 Share on other sites More sharing options...
JasonLewis Posted August 5, 2008 Share Posted August 5, 2008 It could well possibly be that then, I am not very good with the stuff that happens behind the scenes so I can't help the OP any further if that's the case. Link to comment https://forums.phpfreaks.com/topic/118225-solved-problem-with-php-script/#findComment-608458 Share on other sites More sharing options...
peddel Posted August 5, 2008 Author Share Posted August 5, 2008 Well i changed the code to the following : <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> </head> <body> <form id="test" method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>"> <input type="text" name="file" /> <input type="submit" name="button" value="Press here" /> </form> </body> <?php if(isset($_POST['button'])){ print("Ur message : ".$_POST['file']); } ?> </html> Let me stress out that im using aptana, a php devellopment tool. I just use the internal server to test inside the program. It is using firefox to show the result. When i press the button now i get a new page with the message : Can't find page ... Any ideas? Link to comment https://forums.phpfreaks.com/topic/118225-solved-problem-with-php-script/#findComment-608461 Share on other sites More sharing options...
BioBob Posted August 5, 2008 Share Posted August 5, 2008 You could also try temporarily changing your methods from POST to GET so you can read it in your address bar and see if theres anything funky there... so you should end up with something like script.php?hidden=foo. Dont forget to change $_POST to $_GET if you do that tho... Also, try replacing "$_SERVER['REQUEST_URI']; " with $_SERVER['PHP_SELF']; or just the name of your page, script.php will work just fine if thats the name of yoru script. Link to comment https://forums.phpfreaks.com/topic/118225-solved-problem-with-php-script/#findComment-608462 Share on other sites More sharing options...
peddel Posted August 5, 2008 Author Share Posted August 5, 2008 I just tried the action="" thing. Thing is it now does something, but the text still doesnt show up I typ in the box, press the button, then the empty box and button return but no text printed under it Link to comment https://forums.phpfreaks.com/topic/118225-solved-problem-with-php-script/#findComment-608464 Share on other sites More sharing options...
JasonLewis Posted August 5, 2008 Share Posted August 5, 2008 Use WAMP. Um. Confirm the page is saved as a PHP. Make another page, called phpinfo.php and put in this: <?php phpinfo() ?> Save and run it. It could possibly well be a problem with your setup. Link to comment https://forums.phpfreaks.com/topic/118225-solved-problem-with-php-script/#findComment-608465 Share on other sites More sharing options...
peddel Posted August 5, 2008 Author Share Posted August 5, 2008 Use WAMP. Um. Confirm the page is saved as a PHP. Make another page, called phpinfo.php and put in this: <?php phpinfo() ?> Save and run it. It could possibly well be a problem with your setup. ok give me a second, i will try this Link to comment https://forums.phpfreaks.com/topic/118225-solved-problem-with-php-script/#findComment-608466 Share on other sites More sharing options...
BioBob Posted August 5, 2008 Share Posted August 5, 2008 Didnt think of that. If its older and REGISTER GLOBALS is turned on, you could try replacing $_POST wiht $HTTP_POST_VARS['fieldname'] also... If thats the case and HTTP_POST works and $_POST doesnt, plug this in up at the top: $_POST = &$HTTP_POST_VARS; Link to comment https://forums.phpfreaks.com/topic/118225-solved-problem-with-php-script/#findComment-608468 Share on other sites More sharing options...
JasonLewis Posted August 5, 2008 Share Posted August 5, 2008 Didnt think of that. If its older and REGISTER GLOBALS is turned on, you could try replacing $_POST wiht $HTTP_POST_VARS['fieldname'] also... If thats the case and HTTP_POST works and $_POST doesnt, plug this in up at the top: $_POST = &$HTTP_POST_VARS; If that's the case then I would recommend upgrading the version of PHP. Link to comment https://forums.phpfreaks.com/topic/118225-solved-problem-with-php-script/#findComment-608470 Share on other sites More sharing options...
peddel Posted August 5, 2008 Author Share Posted August 5, 2008 this is not the case gimme minute, its not that easy to get WAMP going in this company Link to comment https://forums.phpfreaks.com/topic/118225-solved-problem-with-php-script/#findComment-608473 Share on other sites More sharing options...
peddel Posted August 5, 2008 Author Share Posted August 5, 2008 Ok got WAMP2.0 going ! It clearly worked fully when testing under WAMP, sad i didnt come up with this. I just dont get why Aptana doesnt work, cuz it uses the same browers. Anyone got clue how maybe to solve the problem in aptana? If not ill just check my pages with wamp Link to comment https://forums.phpfreaks.com/topic/118225-solved-problem-with-php-script/#findComment-608475 Share on other sites More sharing options...
JasonLewis Posted August 5, 2008 Share Posted August 5, 2008 I've never used Aptana so I would have no idea. I've always used WAMP. Link to comment https://forums.phpfreaks.com/topic/118225-solved-problem-with-php-script/#findComment-608480 Share on other sites More sharing options...
peddel Posted August 5, 2008 Author Share Posted August 5, 2008 I've never used Aptana so I would have no idea. I've always used WAMP. Well thank you for the help. I never used Aptana at school either, just wamp to test and eclipse to write my php code. It was a friend who showed me the aptana plugin for eclipse. That grew my interest so i dled the free standalone version. Tough now it seems that it has some flaws, no idea how to fix em Thx to everyone for the advice ! U guys will be hearing soon from me again with new php problems Link to comment https://forums.phpfreaks.com/topic/118225-solved-problem-with-php-script/#findComment-608501 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.