Jump to content

Unexplainable problem...


Gorfy

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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"

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.