potential problems with $PHP_SELF?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

lscarmichael
Forum Newbie
Posts: 13
Joined: Mon Mar 07, 2005 6:37 am

potential problems with $PHP_SELF?

Post by lscarmichael »

i have a VERY simple form that takes an email address and adds it to a mysql database. the form works great in firefox but i've been having problems with it in IE. strangely enough, i have other forms that work fine in both browsers. the only difference is that the broken form is using $PHP_self as the action. could this cause a problem? could there be browser options that aren't allowing this to work correctly?

when an email is input the user should simply see "email added" below the input widow (and the window will clear). right now the window just clears but nothing is displayed.

let me know if you need to see code or have any other questions.

thanks

lee
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

you most likely have register globals off.. it is now

$_SERVER['PHP_SELF'] I do believe..
lscarmichael
Forum Newbie
Posts: 13
Joined: Mon Mar 07, 2005 6:37 am

Post by lscarmichael »

this is what i have
<form action="<?php echo $PHP_SELF;?>" method="post" name="signupForm">

so you're saying it should be
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" name="signupForm">

correct?
lscarmichael
Forum Newbie
Posts: 13
Joined: Mon Mar 07, 2005 6:37 am

Post by lscarmichael »

well, i tried that and it doesn't seem to work. any other ideas?
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Whats it actually echoing out to the form? I usually use <?php echo basename($_SERVER['PHP_SELF']);?> .. helps with sub directories..
lscarmichael
Forum Newbie
Posts: 13
Joined: Mon Mar 07, 2005 6:37 am

Post by lscarmichael »

i know you probably didn't want all this but this might clear up any other questions

thanks for your help with this.

lee



<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
</head>

<body>
<body bgcolor="#000000" background="../images/bg.jpg" vlink="#FF00FF">

<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" name="signupForm">
<font face="Verdana" size="2"><input type="text" name="new_email" align="TOP" size="15">
<input type="submit" value="Submit" name="submit" align="MIDDLE" style="font-family: Verdana">
</form>




<?php
include 'functions.php';
//******************************************************
// Check for completed field.
//******************************************************
if (isset($submit)) {
if(!$new_email) {
die("<br>Enter an email address first!");
}
else{
$status = ValidateEmail($new_email);
switch($status){
case 0:
break;
case 1:
die("<br>Invalid address, try again.");
break;
case 2:
die("<br>Invalid address, try again.");
break;
}
connect_and_select_db();
$result = mysql_query("SELECT email FROM mailingList");
$num_rows = mysql_num_rows($result);
for($i=0; $i<$num_rows; $i++){
$email = mysql_result($result,$i,"email");
if($email == $new_email){
die("<br>You're already on the list.");
}
elseif($email != $new_email and $i+1==$num_rows){
mysql_query("INSERT INTO `mailingList` ( `primary ` , `first` , `last` , `email` ) VALUES ('', '', '', '$new_email');");
echo "<br>Address added successfully.";
echo "<br>", $num_rows, " total entries";
}

}
}

}


?>
</body>

</html>
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

edit your post and use code tags around your code, please.
lscarmichael
Forum Newbie
Posts: 13
Joined: Mon Mar 07, 2005 6:37 am

Post by lscarmichael »

sorry it wouldn't let me edit the previous post. here it is again.

Code: Select all

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
</head>

<body>
<body bgcolor="#000000" background="../images/bg.jpg" vlink="#FF00FF">

<form action="<?php echo $_SERVER&#1111;'PHP_SELF'];?>" method="post" name="signupForm">
        <font face="Verdana" size="2"><input type="text" name="new_email" align="TOP" size="15">
        <input type="submit" value="Submit" name="submit" align="MIDDLE" style="font-family: Verdana">
</form>




<?php
include 'functions.php';
//******************************************************
// Check for completed field.
//******************************************************
if (isset($submit)) &#123;
        if(!$new_email) &#123;
                die("<br>Enter an email address first!");
        &#125;
        else&#123;
                $status = ValidateEmail($new_email);
                switch($status)&#123;
                        case 0:
                                break;
                        case 1:
                                die("<br>Invalid address, try again.");
                                break;
                        case 2:
                                die("<br>Invalid address, try again.");
                                break;
                        &#125;
                connect_and_select_db();
                $result = mysql_query("SELECT email FROM mailingList");
                $num_rows = mysql_num_rows($result);
                for($i=0; $i<$num_rows; $i++)&#123;
                        $email = mysql_result($result,$i,"email");
                        if($email == $new_email)&#123;
                                die("<br>You're already on the list.");
                        &#125;
                        elseif($email != $new_email and $i+1==$num_rows)&#123;
                                mysql_query("INSERT INTO `mailingList` ( `primary ` , `first` , `last` , `email` ) VALUES ('', '', '', '$new_email');");
                                echo "<br>Address added successfully.";
                                echo "<br>", $num_rows, " total entries";
                        &#125;

                &#125;
        &#125;
        
&#125;


?>
</body>

</html>
lscarmichael
Forum Newbie
Posts: 13
Joined: Mon Mar 07, 2005 6:37 am

Post by lscarmichael »

any ideas?
User avatar
smpdawg
Forum Contributor
Posts: 292
Joined: Thu Jan 27, 2005 3:10 pm
Location: Houston, TX
Contact:

Post by smpdawg »

I never saw the answer to the question about register_globals. Is it on or off right now?
lscarmichael
Forum Newbie
Posts: 13
Joined: Mon Mar 07, 2005 6:37 am

Post by lscarmichael »

wait, i didn't get what he said about register_globals and the <? ...?> he had after it...should they be on or off? did that php line turn them on or off? i'm confused
you most likely have register globals off.. it is now

$_SERVER['PHP_SELF'] I do believe..
User avatar
smpdawg
Forum Contributor
Posts: 292
Joined: Thu Jan 27, 2005 3:10 pm
Location: Houston, TX
Contact:

Post by smpdawg »

You can check register_globals by running phpinfo() and looking for the entry that mentions register_globals.

If it is off, you will not be able to access post variables, etc. by name and must you the $_POST superglobal instead. BTW - This is the preferred behavior in PHP.

So instead of saying this

Code: Select all

if (isset($submit)) &#123;
You would say

Code: Select all

if (isset($_POST&#1111;'submit'])) &#123;
And this would also apply to the POST variable new_email.
lscarmichael
Forum Newbie
Posts: 13
Joined: Mon Mar 07, 2005 6:37 am

Post by lscarmichael »

nope, they're on...any other ideas? i'm just going to "start over" by adding pieces of code in one at a time to see where it messes up.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

lscarmichael wrote:nope, they're on...any other ideas? i'm just going to "start over" by adding pieces of code in one at a time to see where it messes up.
standard debugging...



One thing I recommend is immediatly turning off Register Globals in your php.ini
lscarmichael
Forum Newbie
Posts: 13
Joined: Mon Mar 07, 2005 6:37 am

Post by lscarmichael »

ok, see what you think of this.

i put an echo after each line of code (starting inside the <?php). it looks like this:

Code: Select all

<?php
echo "<br>in php block";
include 'functions.php';
echo "<br>after include funtions";
//******************************************************
// Check for completed field.
//******************************************************
echo "<br>submit = ", $submit;
if (isset($_POST&#1111;'submit'])) &#123;
echo "<br>in isset";
        if(!$new_email) &#123;
        echo "<br>in if";
                die("<br>Enter an email address first!");
        &#125;
        else&#123;   echo "<br>in else";
and so on......

so, when i fill in my form and hit enter i get:
in php block
after include funtions
submit =
so when i hit the button something fishy is going on...it's like it's not taking the button action...

what could this mean?
Post Reply