Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
| Search | Today's Posts | Mark Forums Read
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 November 20th, 2003, 09:54 PM
Registered User
 
Join Date: Nov 2003
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Newsletter Mailing List Manager

Book: Beginning PHP4

A Newsletter Mailing List Manager
Page: 536



I have been trying to get this to work but I get this message on the newsletter.php screen:

Notice: Undefined variable: action in newsletter.php on line 185

Line 185: user_message("Successfully unsubscribed to $newsletter_name.");}switch ($action){

Also at the newsletter.php screen, I put in my e-mail address and clicked on 'Check Status' and nothing happened...

What can I do?

-Spencer
 
Old December 10th, 2003, 08:09 PM
Registered User
 
Join Date: Dec 2003
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have been researching the whole register_globals issue. Here are some links for you, pyspencer, about your undefined variable problem:

http://p2p.wrox.com/archive/beginnin...2002-11/17.asp
http://p2p.wrox.com/topic.asp?TOPIC_ID=2429
http://www.google.com/search?q=site:...ster%5Fglobals


But your second problem, about nothing happening when submitting a form, is an issue I'm having as well.

I copied and uploaded the code for the newsletter manager (admin_mailer.php) from the book (Beginning PHP4 - Chapter 15) and I can see the the control panel menu when I open the page. But when I press submit, the page reloads to itself. It's very quick, though, so I doubt it's doing anything other than refreshing the page.

I've changed $PHP_SELF to $_SERVER['PHP_SELF'] and deleted global $PHP_SELF (that's what I'm supposed to do right? at least that's the impression I got from all the research).

But the form is still not processing the data.

I've also tried the same thing with a downloaded code file from this webpage, but no luck. In either case, the code is exactly the same as in the book except for the changes I mentioned above. I just started learning php last week, so I have no idea what's wrong.

Any help would be greatly appreciated.

 
Old December 10th, 2003, 08:34 PM
Friend of Wrox
Points: 2,570, Level: 21
Points: 2,570, Level: 21 Points: 2,570, Level: 21 Points: 2,570, Level: 21
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: San Diego, CA, USA
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

$action is a variable that's submitted via an HTML form, so when fixing scripts to work with register_globals = off, you should've changed this to $_GET['action'] or $_POST['action'], depending on the form method.


Take care,

Nik
http://www.bigaction.org/
 
Old December 11th, 2003, 02:17 PM
Registered User
 
Join Date: Dec 2003
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks for the quick reply. Sorry to pester you, but a few more questions. By the way, I know this is a bad way to learn php. It'd be better to learn the basic concepts and solve my own problems along the way. But I'm under pressure to create a specific program and I just want to get this thing over with so I can start from the beginning and learn php properly.


1) I adjusted the $action variables. Now when I hit submit, the page refreshes but this time it becomes blank. It's a step ahead though because after commenting out portions of the code, I was able to verify that it was starting to work.

I think the problem is here:

function admin_menu_form() {
    global $newsletters_table;
    db_connect();

How do I edit "global $newsletters_table;" to work with register_globals = off?


2) Is the following correct?

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">


3) I want to turn register_globals setting ON to show my boss that this is the problem (he won't listen to me). I edited the php.ini file which I had previously saved in c:\winnt\, but when I checked my php settings with php_info, register_globals was still off. I even copied php.ini to the "system" and "system32" folders in "winnt," but to no avail.

How do I change register_global to ON? I'm using win2000 and a local IIS server.

 
Old December 11th, 2003, 02:30 PM
Friend of Wrox
Points: 2,570, Level: 21
Points: 2,570, Level: 21 Points: 2,570, Level: 21 Points: 2,570, Level: 21
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: San Diego, CA, USA
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

No problem. Okay, responses:

1) If $newsletters_table is a variable defined in global scope of the script, you don't need to do anything to get it to work. If $newsletters_table is created from HTML form input, then you'll need to access it via $_GET or $_POST.

More clarification:

<?php

function do_stuff()
{
    global $some_var;
    echo $some_var;
}

function change_it()
{
    global $some_var;
    $some_var = "Changed!";
}

$some_var = "Hello, world.";

do_stuff(); // prints "Hello, world."
change_it();
do_stuff(); // prints "Changed!"


$some_var = "Goodbye.";

do_stuff(); // prints "Goodbye."
change_it();
do_stuff(); // prints "Changed!"

?>


See, what the 'global' keyword does is import a global variable into the local function scope. Normally, variables declared within a function are ONLY visible within that function, and their values go away as soon as the function ends.

For more info:
  http://www.php.net/variables.scope


2) Yes.


3) The output of phpinfo() should tell you which php.ini file is being used to set the variables. If you have PHP running as an ISAPI module, you have to restart IIS for configuration changes to take effect. That's because IIS loads the PHP interpreter into memory when it starts up. PHP parses php.ini on startup only, so changes to the configuration file won't take effect until PHP is restarted.

If, for some reason, you have PHP running as a CGI, then IIS doesn't load the PHP interpreter in memory, it runs the php.exe application every time a script is run. This means that PHP processes php.ini for EVERY SCRIPT that's executed on your system. This has the benefit of having configuration changes become active immediately, but it's incredibly inefficient and prone to security risks.



Take care,

Nik
http://www.bigaction.org/
 
Old December 21st, 2003, 07:20 AM
Registered User
 
Join Date: Nov 2003
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I can't believe this. I looked past something so simple as this. I changed all the actions to "$_POST['action']" since my form's method is "post".

Why did they add register_globals to PHP? Seems like they cause more problems than they fix.

-Spencer
 
Old December 21st, 2003, 07:13 PM
Friend of Wrox
Points: 2,570, Level: 21
Points: 2,570, Level: 21 Points: 2,570, Level: 21 Points: 2,570, Level: 21
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: San Diego, CA, USA
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default


Quote:
quote:
Why did they add register_globals to PHP? Seems like they cause more problems than they fix.
  http://www.php.net/security.registerglobals


Take care,

Nik
http://www.bigaction.org/




Similar Threads
Thread Thread Starter Forum Replies Last Post
About Mailing List ssomchai BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 0 May 5th, 2008 10:05 PM
Mailing List Carriemh Beginning PHP 2 September 2nd, 2006 07:17 AM
Add Mailing List Problem USADarts BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 August 11th, 2004 10:19 PM
Mailing list module has error - HELP drfunkie BOOK: ASP.NET Website Programming Problem-Design-Solution 3 September 8th, 2003 12:09 PM
mailing list using php dungey PHP How-To 1 June 4th, 2003 02:50 PM





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