Gorfy Posted March 5, 2009 Share Posted March 5, 2009 I must admit upfront that I am quite new to PHP, but I am not new to OOP, so I understand most of it. Can anyone possibly explain this: <form method="POST" action="scripts/cookieSet.php"> <input type="hidden" name="neededvar" value="HELLO"> then in my cookieSet.php file I echo $_POST['neededvar'] it prints HELLO, so I know stuff is working, but if I change that form code to: <form method="POST" action="scripts/cookieSet.php"> <input type="hidden" name="neededvar" value="<?php $url=$_SERVER['REQUEST_URI']; echo $url; ?>"> then it doesn't echo anything, just a blank page. I have been struggling with this for hours... I've tried everything I can think of and searched about 10 different forums, not to mention like 5 different syntax manuals. Since the first example works, I know that php is working at least partially. However another thing that is confusing me is that if I put this in the middle of my html page: <?php print "Hello" ?> it does not appear on the page, nothing happens. Yet I have seen this example in tons of tutorials. Quote Link to comment Share on other sites More sharing options...
btherl Posted March 5, 2009 Share Posted March 5, 2009 PHP's default behaviour is to display a blank page if there is an error parsing the script. If you post your full script we can tell you where the error is. Otherwise you can switch on the "display_errors" ini directive in apache. You can't switch it on in the script itself, as the error occurs before the script executes. Or if you have access to a command line version of php, just run the script there. It will display the errors. Quote Link to comment Share on other sites More sharing options...
Gorfy Posted March 5, 2009 Author Share Posted March 5, 2009 There are no errors in the script. The script is: <?php $test = $_POST['neededvar']; echo $test; ?> And it works with the html like this: <form method="POST" action="scripts/cookieSet.php"> <input type="hidden" name="neededvar" value="HELLO"> It prints HELLO. But when I change the html to this: <form method="POST" action="scripts/cookieSet.php"> <input type="hidden" name="neededvar" value="<?php $url=$_SERVER['REQUEST_URI']; echo $url; ?>"> It prints nothing, just a blank page. Is my syntax correct in the html form code? That's mainly what I'm concerned with. Or do you think that it's passing the http path correctly as a string, but for some reason my simple script can't echo it? Quote Link to comment Share on other sites More sharing options...
btherl Posted March 5, 2009 Share Posted March 5, 2009 If it prints a blank page, then there IS an error in the script. The next step is to find the error and fix it. Can you post the entire script please? Quote Link to comment Share on other sites More sharing options...
ScotDiddle Posted March 5, 2009 Share Posted March 5, 2009 Gorfy , I ran your script and it worked fine... HTML input tag with the "hidden" attribute are just that... hidden... When you "View Source" through a browser, you will see that the script wrote the "needvar" element just fine. Here's the output I got from Zend Studio 5.5.0 : <form method="POST" action="scripts/cookieSet.php"> <input type="hidden" name="neededvar" value=" /test.php?start_debug=1&debug_port=10000&debug_fastfile=1&debug_host=172.16.150.54%2C127.0.0.1&send_sess_end=1&debug_no_cache=1236254378128&debug_stop=1&debug_url=1&debug_new_session=1"> </body> </html> Scot L. Diddle, Richmond VA Quote Link to comment Share on other sites More sharing options...
Gorfy Posted March 6, 2009 Author Share Posted March 6, 2009 Okay here is the code for my test.html: <html> <head> <title>test</title> </head> <body> <Form method="POST" action="scripts/test.php"> <input type="hidden" name="neededvar" value="<?php echo $_SERVER['REQUEST_URI']; ?>"> <input type="submit" value="Submit"> <input type="reset" value="Reset"> </Form> </body> </html> And here is the code for my test.php: <?php echo 'neededvar = '; echo $_POST['neededvar']; ?> Pretty simple stuff... yet it only prints: neededvar = and when I view source it shows: neededvar = <?php echo $_SERVER['REQUEST_URI']; ?> is there something wrong with a server setting? Because like I said in my original post, if I replace that php with a string in the html form value, it works just fine... Quote Link to comment Share on other sites More sharing options...
btherl Posted March 6, 2009 Share Posted March 6, 2009 If you are seeing php in your source, then yes that is a server configuration issue. It means php is not executing. It's likely that it's not executing because you called it test.html instead of test.php, and the server is only configured to recognize php in files that end in ".php" Quote Link to comment Share on other sites More sharing options...
DamienRoche Posted March 6, 2009 Share Posted March 6, 2009 Can't believe nobody noticed. I believe it's because the php is inside a html file: test.html You cannot run php inside html files. Save it as php and try again. Hope that helps. Quote Link to comment Share on other sites More sharing options...
Gorfy Posted March 6, 2009 Author Share Posted March 6, 2009 Wow. I didn't realize that. Sorry to waste yall's time and thanks! Quote Link to comment 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.