Solved

Undefined variable: PHP_SELF in PHP4.0 on Win2000 server

Posted on 2002-06-05
9
435 Views
Last Modified: 2008-03-17
I have a code:
<?php
$hostname="sonpham.24mbnet.com";
$username="root";
$database="SE";
$ma = isset ($ma)? $ma:'';
$tien = isset($tien)?$tien:0;
$cmd= isset ($cmd)? $cmd:'';
$myConnect=mysql_connect($hostname,$username);
if (!$myConnect) {$msgErr = "Can not Connect to MySQL Server<Br>\t\t".mysql_error() ."<Br><Br>\n";     print $msgErr;}
mysql_select_db($database,$myConnect);
switch ($cmd) {
     case 'OK':
          $laygio = getdate();
          $thoigian= $laygio["hours"].":".$laygio["minutes"].":".$laygio["seconds"];
          mysql_query("insert into thanhvien(MAuser)values('$ma')") or die( 'Khong nhap duoc'.  mysql_error());
          $ttx=($tien-$tien)/$tien;
          mysql_query("insert into tk_tienvao(MAuser,Thoigian,Tienvao,tiensudung,tx)values('$ma','$thoigian','$tien','$tien','$ttx')") or die( 'Khong nhap duoc'.  mysql_error());
          break;
    default:
}
     $result=mysql_query("select * from tk_tienvao");
     $recc=mysql_num_rows($result)+1;
     print "<HTML>";
     print "<BODY leftmargin=30 bgColor='#CCCCFF' onLoad='moveTo(80,250)'><br><br>";
     print "<CENTER><FORM method='POST' name='me' action=".$PHP_SELF.">";
     print "<TABLE border=1 bordercolor='#0000FF' bgColor='#330066' width='100%' style='color:#FFFF00' align=center>";  
     print "<TR width='100%' align=center><TD style='font-family:Times New Roman;font-size:14;color:#FFCCFF' colspan=2>S&#7889; l&#432;&#7907;ng ng&#432;&#7901;i m&#7903; tài kho&#7843;n là:<b style='color:#FFFF00'>".($recc-1)."</B></TD></TR>";
     print "<TR width='100%' align=center>";
     print"          <TD colspan=2 width='100%' style='color:#00FF00;font-weight:bold;font-size:20px'>CREATE NEW ACCOUNT</TD></TR><TR align=center><TD style='font-size:15px;color:#FFFF00;font-weight:bold'>USERNAME</TD>";
     print "     <TD><INPUT type='text' name='ma' value='QSE'></TD></TR><TR align=center><TD style='font-size:15px;color:#FFFF00;font-weight:bold'>CASH</TD>          <TD><INPUT TYPE='text' NAME='tien' value='100000'></TD></TR><TR align=center><TD style='font-size:15px;color:#FFFF00;font-weight:bold' Colspan=2><INPUT TYPE='submit' value='OK' name='cmd' style='cursor:hand'>&nbsp;&nbsp;&nbsp;<INPUT type='Reset' value='Reset' style='cursor:hand'>&nbsp;&nbsp;&nbsp;<INPUT type='button' value='Exit' onClick='window.close()' style='cursor:hand'></TD></TR></TABLE></FORM></CENTER></BODY></HTML>";
mysql_close();
?>
 But when run then the browse show: Notice: Undefined variable: PHP_SELF in D:\php&mysql\QSE_SON\Qse\data\nao.php on line 25
 I still run well on Win98se or WinNT but not run on Win2000. Can you help me? I'am very need! Thank You very much!

0
Comment
Question by:rosepaint
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 40

Accepted Solution

by:
Richard Quadling earned 50 total points
ID: 7055774
If you are using V4.2 (I think), then $PHP_SELF is now $_SERVER["PHP_SELF"]

Regards,

Richard.
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 7055813
Also, if this code is in a function, you MAY have to use the globals array.

But as of V4.2 (I think), all that has more or less gone. You use $_SERVER, $_POST, $_GET, $_COOKIE instead. They are always global too.

Regards,

Richard.
0
 
LVL 5

Expert Comment

by:dkjariwala
ID: 7056066
All those $_SERVER, $_POST etc. are SUPER GLOBAL.  You can access from the functions without declaring them global.

JD
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 1

Assisted Solution

by:onestar
onestar earned 50 total points
ID: 7056498
If you are using us 4.21 there are some changes that I have made to scripts that seem to be making them work better.


First of all when posting to self this is the best way

if($_POST['form_submitted'] == 1)
{
     //do something ....
}
else
{
     //display form
     <form method="post" action="<?=$PHP_SELF?>">
     <input type="hidden" name="form_submitted" value="1">
}

You should send a hidden field and check that.
This will make sure if the user hits enter or clicks the submit button or hits enter on the submit buttom it will always work. You should never just do if($submit) I have found cases where it doesn't work.

Another thing you should always use
if (isset($category_id))
not just
if ($category_id)


Another HUGE issue is now they are trying to faze-out register_globals.

If you have writen your scripts the old way without using SUPER GLOBALS you need changed your php.ini to register_globals = On
or change all your scripts to use SUPER GLOBALS

This was the default setting in older versions of php.

//This is the part of the php.ini file 4.21
; You should do your best to write your scripts so that they do not require
; register_globals to be on;  Using form variables as globals can easily lead
; to possible security problems, if the code is not very well thought of.
register_globals = Off
// **** Change to "On" *****


Hope this helps
Onestar



0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 7056680
I like that form submitter idea! Very clever.
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 7056717
Also, something that may help with those repeated print statements.

Instead of ...

print "a whole load of text";
print "and";
print "some";
print "more";
...

try

print <<< _END_
a whole load of text
and
some more
_END_;



This is from the PHP manual ...

<?php
$str = <<<EOD
Example of string
spanning multiple lines
using heredoc syntax.
EOD;

/* More complex example, with variables. */
class foo
{
    var $foo;
    var $bar;

    function foo()
    {
        $this->foo = 'Foo';
        $this->bar = array('Bar1', 'Bar2', 'Bar3');
    }
}

$foo = new foo();
$name = 'MyName';

echo <<<EOT
My name is "$name". I am printing some $foo->foo.
Now, I am printing some {$foo->bar[1]}.
This should print a capital 'A': \x41
EOT;
?>


Regards,
Richard.
0
 
LVL 11

Expert Comment

by:shmert
ID: 9643358
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
SPLIT: rquadling, onestar
Please leave any comments here within the next seven days.
               
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
               
Sam Barnum
EE Cleanup Volunteer              
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses how to implement server side field validation and display customized error messages to the client.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

697 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question