Wrox Programmer Forums
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 28th, 2004, 01:29 AM
Authorized User
 
Join Date: Apr 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to coitri Send a message via MSN to coitri Send a message via Yahoo to coitri
Default Variable

Hi all, lps help me!
I have a page (index.php) contain two links:
<a href=index.php?act=home>Home</a>
and
<a href=index.php?act=about>About</a>

In the index.php, I code:
<%
if ($act=="home"){
 include("index.php");
}
if ($act=="about"){
 include("about.php");
}
%>


Then, I run from browser, http://localhost/learn/index.php
I get this error: Undefine variable $act in index.php line 12


How to fix this error??
I use: PHP 5 RC 2/OS WinXP, WIn2003/IIS 6.0

Thanks in advance!!

 
Old April 28th, 2004, 01:36 AM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

You need to reference the variable via a superglobal.

Use $_GET['act'] instead of $act, since the variable is being passed via the GET method.

So...

<?php
    if ($_GET['act'] == 'home')
    {
      ...etc


Regards,
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::
 
Old April 28th, 2004, 06:54 AM
Authorized User
 
Join Date: Apr 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to coitri Send a message via MSN to coitri Send a message via Yahoo to coitri
Default

thanks Rich,
to avoid modify, I added statement: $act = $_GET['act']; before if ($act...

it done!

Thanks again!

 
Old April 28th, 2004, 07:29 AM
Authorized User
 
Join Date: Aug 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to spraveens
Default

Hi

Just Add

register_globals = on

in the Php.ini File and you can use the $act directly instead of

$_GET["act"].


Praveen

 
Old April 28th, 2004, 09:51 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Assuming they have access to the php.ini file, and aren't using a hosting company with a shared server...

(Hell, they could completely recomplie PHP with globals switched on, as well, if they really wanted - assuming they have access to the bash shell! :)

coitri, sticking with the consensus makes your scripts more portable: my advice is, use the superglobal $_GET array values.
 
Old May 5th, 2004, 10:04 PM
Registered User
 
Join Date: May 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to tensaix2j
Default

hi,
i have just bought the book a few days ago, and i was also encountering a problem regarding undefined variable when i was trying the examples in chapter3 regarding post and get...

and i m not quite understand where to add this in php.ini..

register_globals = on

becoz after adding in, i still get the same error..

http://www.circles99.com/elements/al...46272/t_FS.GIF
 
Old May 6th, 2004, 08:45 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Jiong:

You need to change the part where it says 'register_globals = off', not add a new statement. Just erase 'off' and type 'on'.

BTW, why don't you just use $_GET and $_POST?

HTH,

Snib

<><
 
Old May 7th, 2004, 10:16 AM
Authorized User
 
Join Date: Apr 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to coitri Send a message via MSN to coitri Send a message via Yahoo to coitri
Default

I contacted my hosting company, and they turn ON register_globals for me.

Thanks for your help,

Coitri

 
Old May 31st, 2004, 09:04 PM
Authorized User
 
Join Date: Apr 2004
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to junemo
Default

Hi, pls help me...
I have a login page (login.php):

//check if user is coming from a form
if ($_POST['op'] == "ds") {

//check username and password
if (($_POST[username] != "admin") || ($_POST[password] != "inv123")) {

//handle bad login
$msg = "<P><strong> <center>You Are Not Authorized!!</center> </strong></P>";
        $show_form = "yes";

} else {

        //handle good login
        $valid = "yes";
        $_SESSION[valid] = $valid;
        $show_menu = "yes";
    }

} else {

    //determine what to show
    if ($valid == "yes") {
        $show_menu = "yes";
    } else {
        $show_form = "yes";
    }
}

//build form block
$form_block ="
<p></p>
<p></p>

<h1><center>Administrator</center></h1>
<form method=POST action=\"$_SERVER[PHP_SELF]\">

$msg
<b><center>Please enter username and password: </center></b>
<P align=center><strong>Username:</strong><br>
<input type=\"text\" name=\"username\" size=15 maxlength=25></P>

<P align=center><strong>Password:</strong><br>
<input type=\"password\" name=\"password\" size=15 maxlength=25></P>

<input type=\"hidden\" name=\"op\" value=\"ds\">

<P align=center><input type=\"submit\" name=\"submit\" value=\"Login\">
                <input type=\"reset\" name=\"reset\" value=\"Cancel\"></P>

</FORM>";

//build menu block
$menu_block ="

<h1><center>Proforma Invoice System</center></h1>
<P align=center><strong>&nbsp; &nbsp; Administration Menu</strong></p>[list]<center>
<li><a href=\"addform.php\">Add a New Invoice</a>
<li><a href=\"mod.php\">Modify an Existing Invoice</a>
<li><a href=\"del.php\">Delete an Existing Invoice</a>
<li><a href=\"admin_logout.php\">Logout</a>

</center></ul>
<P align=center><strong>View Records</strong>[list]
<li><center><a href=\"show_inv.php\">Show All Invoices.<center></a>
</ul></p>";

//assign the block to show to the $display_block variable
if ($show_form == "yes") {
    $display_block = $form_block;
} else if ($show_menu == "yes"){
    $display_block = $menu_block;
}

?>

When I run at browser, http://192.168.0.9/inv/login.php
I get this error:
Notice: Undefined index: op in C:\Inetpub\wwwroot\inv\login.php on line 15
Notice: Undefined variable: valid in C:\Inetpub\wwwroot\inv\login.php on line 35
Notice: Undefined variable: msg in C:\Inetpub\wwwroot\inv\login.php on line 52

How to fix it?
I use PHP4 Win2000 Service Pack 4 IIS 5.0

Thanks in advance!!!





 
Old May 31st, 2004, 09:18 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

1) You are missing a number of semi-colons.
2) You need to put quotes around indexes (is it indexi? whatever) i.e. $_SESSION['valid'] instead of $_SESSION[valid]

Try this and see if it throws any other errors.

HTH,

Snib

<><





Similar Threads
Thread Thread Starter Forum Replies Last Post
Object variable or With block variable not set haidee_mccaffrey Classic ASP Professional 5 March 8th, 2007 03:34 PM
ASSIGNING A JAVA SCRIPT VARIABLE TO A XSL VARIABLE SOMANATHAN10 XSLT 1 February 21st, 2007 04:26 AM
object variable or with block variable not set Aoude BOOK: Beginning VB.NET Databases 1 February 24th, 2006 05:21 PM
Object variable or With block variable not set tparrish Pro VB Databases 1 May 25th, 2005 02:08 PM
Object variable or with block variable not set spacy ASP.NET 1.x and 2.0 Application Design 0 September 21st, 2004 12:19 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.