|
Subject:
|
Newsletter Mailing List Manager
|
|
Posted By:
|
PySpencer
|
Post Date:
|
11/20/2003 8:54:15 PM
|
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
|
|
Reply By:
|
minguy
|
Reply Date:
|
12/10/2003 7:09:36 PM
|
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/beginning_php/2002-11/17.asp http://p2p.wrox.com/topic.asp?TOPIC_ID=2429 http://www.google.com/search?q=site:p2p%2Ewrox%2Ecom+register%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.
|
|
Reply By:
|
nikolai
|
Reply Date:
|
12/10/2003 7:34:37 PM
|
$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/
|
|
Reply By:
|
minguy
|
Reply Date:
|
12/11/2003 1:17:45 PM
|
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.
|
|
Reply By:
|
nikolai
|
Reply Date:
|
12/11/2003 1:30:37 PM
|
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/
|
|
Reply By:
|
PySpencer
|
Reply Date:
|
12/21/2003 6:20:07 AM
|
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
|
|
Reply By:
|
nikolai
|
Reply Date:
|
12/21/2003 6:13:07 PM
|
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/
|