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 December 17th, 2004, 12:51 AM
Authorized User
 
Join Date: Jun 2003
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default is it wise?

been getting this message ever since i install php4 on my home pc. it does not have this problem when i boot up the same files on my previous office computer.

error
=====
PHP Notice: Undefined index: actionflag in D:\SAV\login.php on line 7 PHP Notice: Undefined index: Userid in D:\SAV\login.php on line 8 PHP Notice: Undefined index: Password in D:\SAV\login.php on line 9

i mean i have this on my login page at the begining

Code
====
<?php
   include("includes/dblib.inc");
   include("includes/clublib.inc");

    $message="";

    $actionflag = $_POST['actionflag'];
    $Userid = $_POST['Userid'];
    $password = $_POST['Password'];

.. more codes ..
?>

i was thinking whether is it good to turn off error reporting?
error_reporting = E_ALL

i don't have this problem previously.
Can some 1 guide mw as to wat is causing this problems?

thanks.
 
Old December 17th, 2004, 11:28 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Replace those assignment lines with something like this:

$actionflag = (isset($_POST['actionflag']))? $_POST['actionflag'] : "";

hth

-Snib - http://www.snibworks.com
Where will you be in 100 years?
 
Old December 17th, 2004, 01:55 PM
Authorized User
 
Join Date: Dec 2004
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to peg110
Default

Quote:
quote:Originally posted by kuehhc

i was thinking whether is it good to turn off error reporting?
error_reporting = E_ALL
Certainly Error reporting is the issue. It's not really an error. It's just a NOTICE. Basically it's saying that you looked for a variable in an array (THe array is the $_POST array) and the index specified was not found. Thus the value for that INDEX was not sent.

As SNIB points out, you could use the ISSET in a tertiary function. I like to use the !empty() i.e. :

$actionflag = !empty($_POST['actionflag'])? $_POST['actionflag'] : "";

This is the same as :

if (!empty ($_POST['actionflag'])) {
      $actionflag = $_POST['actionflag'];
  } else {
      $actionflag = "";
  }



Paul Gardner
------------------
PHP-LIVE help
Via Web @ http://www.mnetweb.co.uk/irc
Via IRC Client pgardner.net:6667
room #PHP
 
Old December 17th, 2004, 11:51 PM
Authorized User
 
Join Date: Jun 2003
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi snib and peg110,

i did this and everything was okay

error_reporting = E_ALL & ~E_NOTICE

but i doubt its the correct way. It simply ignore all the notice which peg110 have pointed out.

snib, if i were to post back a dozen of then variables, for examples a update particulars form, then i will need to do all those isset checking?

from my form

    $actionflag = $_POST['actionflag'];
    $savid = $_POST['savid'];
    $surname = $_POST['surname'];
    $givenname = $_POST['givenname'];
    $dob = $_POST['dob'];
    $datepass = $_POST['datepass'];
    $nric = $_POST['nric'];
    $telhome = $_POST['telhome'];
    $telmobile = $_POST['telmobile'];
    $************ = $_POST['************'];
    $email = $_POST['email'];
    $addr1 = $_POST['addr1'];
    $addr2 = $_POST['addr2'];
    $addr3 = $_POST['addr3'];
    $pcode = $_POST['pcode'];

    $day = $_POST['day'];
    $month = $_POST['month'];
    $year = $_POST['year'];

thx.
 
Old December 20th, 2004, 12:09 PM
Authorized User
 
Join Date: Dec 2004
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to peg110
Default

Well actually, since it appears you are just creating easier to type variables (from the Super Global Array of $_POST ), you could do what I often like to do.


    foreach ($_POST as $index => $content) {
        $$index = $content; //note the DOUBLE $ for $$index
   }


This will take a LONG list of POSTed variables and convert them into a local variable with the same name as the index. It will also avoid the ISSET since it will only create a local variable if it was POSTed.



Paul Gardner
------------------
PHP-LIVE help
Via Web @ http://www.mnetweb.co.uk/irc
Via IRC Client pgardner.net:6667
room #PHP





Similar Threads
Thread Thread Starter Forum Replies Last Post
Random Rows Priority Wise Muhammad Zeeshan SQL Language 0 November 23rd, 2007 03:48 AM
Update Column Serial Wise cancer10 Classic ASP Databases 9 October 23rd, 2006 10:46 AM
fetching Recordset stage wise in to RS yugandhar VB How-To 2 October 7th, 2004 07:32 AM
how to arrange elements group wise. srini XSLT 0 February 4th, 2004 05:17 AM





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