By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,948 Members | 838 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,948 IT Pros & Developers. It's quick & easy.

form action = <?=$_SERVER['PHP_SELF']?> - stopped working

P: n/a
My form action code to submit values to itself have stopped working using
the code

form action = <?=$_SERVER['PHP_SELF']?>

This code used to work

My web host recently told me they enabled phpsuexec option in apache which
apparently needs me to CHMOD my PHP page to 750 and the directory to 755. (I
don't know what this means but know how to CHMOD files). I have CHMODed the
files this but my PHP page doesn't work with those settings, so I set them
back.

Thanks in advance for any help.

Best regards,

tHatDudeUK
Jul 17 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
On Thu, 13 Jan 2005 19:54:06 -0000, "tHatDudeUK"
<th********@gmail.com.removethisbit> wrote:
My form action code to submit values to itself have stopped working using
the code

form action = <?=$_SERVER['PHP_SELF']?>
You've got some extra spaces and missing quotes there. A step in the right
direction would be:

<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>">
This code used to work

My web host recently told me they enabled phpsuexec option in apache which
apparently needs me to CHMOD my PHP page to 750 and the directory to 755. (I
don't know what this means but know how to CHMOD files). I have CHMODed the
files this but my PHP page doesn't work with those settings, so I set them
back.


Define "doesn't work". What does it do? What do you get in the HTML output?
How does it differ from before?

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #2

P: n/a

"Andy Hassall" <an**@andyh.co.uk> wrote in message
news:oa********************************@4ax.com...
You've got some extra spaces and missing quotes there. A step in the right
direction would be:

<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>">
I've cut and paste that and no joy :-(
Define "doesn't work". What does it do? What do you get in the HTML
output?
How does it differ from before?


I'll put all the relevant code at the bottom of this page so you can examine
it. It doesn't work as in the values don't appear to be submitted to itself
as in it won't print the error message if a box isn't ticked, and it won't
forward to the page if it is ticked. It did work before! I'm not really very
conversant with PHP although I managed to put this together myself with a
little forum help etc. All I really need is the two tick boxes, to give an
error message if not ticked, and to take to the appropriate page if ticked.

<?php
$message1 = "";
$message2 = "";
if (isset($Submit) && $Submit == "I consent and wish to participate")
{
if ($_POST[withdraw]!= "Yes")
{
$message1 = "You must tick the box in order to continue";
}
if ($_POST[noanswer]!= "Yes")
{
$message2 = "You must tick the box in order to continue";
}
if ($message1 == "" && $message2 == "")
{
header("Location: http://www.an1.co.uk/survey");
}
}
?>

<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>"
method="post" name="form1" class="style4">
<p align="left">
<input name="withdraw" type="checkbox" id="withdraw6"
value="Yes">
I understand that I may withdraw
from this investigation at any stage <br>
<span class="style3">
<?php
if ($message1!= "")
{
print "$message1";
}
?>
</span> </p>
<p align="left">
<input name="noanswer" type="checkbox" id="noanswer6"
value="Yes">
I understand that I am free to choose not to
answer a question without giving a reason why
<br>
<span class="style3">
<?php
if ($message2!= "")
{
print "$message2";
}
?>
</span> </p>
<p align="left">
<input type="submit" name="Submit" value="I consent and wish
to participate">
</p>
</form>
Jul 17 '05 #3

P: n/a
tHatDudeUK wrote:
if (isset($Submit) && $Submit == "I consent and wish to participate")


I'm guessing your ISP also turned register_globals off, meaning $Submit
needs to be replaced with $_POST['Submit']. Basically, if
register_globals is turned off, $Submit will never be set, and your
statement will always evaluate to false.

It's also a good idea to surround associative array keys with single
quotes if they're literals (i.e. if they're not numbers or variables).

$myvar['key'] is good, $myvar[key] isn't.
$myvar[$key] is good, $myvar['$key'] isn't.

I doubt that's causing your problem here though, but making a habit of
doing it like that will decrease the chance of you running into trouble
at some point due to conflict between an array key and a constant. I
learned this the hard way ;)
Roy W. Andersen
--
ra at broadpark dot no / http://roy.netgoth.org/

"Hey! What kind of party is this? There's no booze
and only one hooker!" - Bender, Futurama
Jul 17 '05 #4

P: n/a

"Roy W. Andersen" <ro******@netgoth.org> wrote in message
news:34*************@individual.net...
tHatDudeUK wrote:
if (isset($Submit) && $Submit == "I consent and wish to participate")


I'm guessing your ISP also turned register_globals off, meaning $Submit
needs to be replaced with $_POST['Submit']. Basically, if register_globals
is turned off, $Submit will never be set, and your statement will always
evaluate to false.


Ok many thanks, looks like I have that bit sorted. Now I have a different
problem.I get the following error message when it should send me to the page
I want it to go to.

Warning: Cannot modify header information - headers already sent by (output
started at /home/an1cou/public_html/musicdownloading/index.php:2) in
/home/an1cou/public_html/musicdownloading/index.php on line 17

line 17 of the code is this one
Jul 17 '05 #5

P: n/a

"Roy W. Andersen" <ro******@netgoth.org> wrote in message
news:34*************@individual.net...
tHatDudeUK wrote:
if (isset($Submit) && $Submit == "I consent and wish to participate")


I'm guessing your ISP also turned register_globals off, meaning $Submit
needs to be replaced with $_POST['Submit']. Basically, if register_globals
is turned off, $Submit will never be set, and your statement will always
evaluate to false.


Ok many thanks, looks like I have that bit sorted. Now I have a different
problem.I get the following error message when it should send me to the page
I want it to go to.

Warning: Cannot modify header information - headers already sent by (output
started at /home/an1cou/public_html/musicdownloading/index.php:2) in
/home/an1cou/public_html/musicdownloading/index.php on line 17

line 17 of the code is this one

header("Location: http://www.an1.co.uk/survey");
Jul 17 '05 #6

P: n/a
On Thu, 13 Jan 2005 21:22:29 -0000, "tHatDudeUK"
<th********@gmail.com.removethisbit> wrote:

"Roy W. Andersen" <ro******@netgoth.org> wrote in message
news:34*************@individual.net...
tHatDudeUK wrote:
if (isset($Submit) && $Submit == "I consent and wish to participate")
I'm guessing your ISP also turned register_globals off, meaning $Submit
needs to be replaced with $_POST['Submit']. Basically, if register_globals
is turned off, $Submit will never be set, and your statement will always
evaluate to false.


Ok many thanks, looks like I have that bit sorted. Now I have a different
problem.I get the following error message when it should send me to the page
I want it to go to.

Warning: Cannot modify header information - headers already sent by (output
started at /home/an1cou/public_html/musicdownloading/index.php:2) in


OK, so what's line 2?
/home/an1cou/public_html/musicdownloading/index.php on line 17

line 17 of the code is this one

header("Location: http://www.an1.co.uk/survey");


See http://php.net/header

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #7

P: n/a
.oO(Roy W. Andersen)
It's also a good idea to surround associative array keys with single
quotes if they're literals (i.e. if they're not numbers or variables).


It's an even better idea to set error_reporting to E_ALL in the php.ini,
then PHP will complain about such things.

Micha
Jul 17 '05 #8

P: n/a
tHatDudeUK wrote:
Warning: Cannot modify header information - headers already sent by (output
started at /home/an1cou/public_html/musicdownloading/index.php:2) in
/home/an1cou/public_html/musicdownloading/index.php on line 17

line 17 of the code is this one

header("Location: http://www.an1.co.uk/survey");


In the script you posted, that line is #16 if you count the line with
<?php as #1, which probably means you have a linebreak before your <?php
tag (or you didn't post the beginning of the script previously).

Headers must be sent before any actual content of the page. If you start
your page with a linebreak (or anything else) then that becomes a part
of the page, and hence once it's been sent to output you can't send any
more headers.

So, as your error explains, the actual page output started at line #2 of
index.php, which means you can't send a header on line #17. If you want
to redirect to a different page after you've started the output you'll
have to use a meta-tag or clientside script.
Roy W. Andersen
--
ra at broadpark dot no / http://roy.netgoth.org/

"Hey! What kind of party is this? There's no booze
and only one hooker!" - Bender, Futurama
Jul 17 '05 #9

P: n/a

"Roy W. Andersen" <ro******@netgoth.org> wrote in message
news:34*************@individual.net...
In the script you posted, that line is #16 if you count the line with
<?php as #1, which probably means you have a linebreak before your <?php
tag (or you didn't post the beginning of the script previously).


Doh, silly me. All working now. Many thanks everyone...
Jul 17 '05 #10

P: n/a
.oO(Roy W. Andersen)
So, as your error explains, the actual page output started at line #2 of
index.php, which means you can't send a header on line #17. If you want
to redirect to a different page after you've started the output you'll
have to use a meta-tag or clientside script.


Never use unreliable client-side redirections if you're able to do it
properly with a server-side script. If necessary use output control
functions.

Micha
Jul 17 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.