55 users online (1 members and 54 guests)  


  Results 1 to 5 of 5

Related

  1. Replies: 8
  2. Replies: 0
  3. What made you choose your present web host?    Forum: Web Hosting Forum
    Replies: 2
  4. For how long are you with your present host?    Forum: Web Hosting Forum
    Replies: 0
  5. Error MySQL Error: 1064 - subqueries    Forum: PHP Forum
    Replies: 0
  1. #1
    snowweb's Avatar
    New User

    Status
    Offline
    Join Date
    Jan 2006
    Posts
    7

    Question error when $_POST is not present

    How can I get over the error when an expected variable is not passed in the URL?
    In my script I have 2 variables, either of which may be passed in the url or none at all.
    The page is capable of rendering without them except an error is producted "undefined index
    in ProdID.
    Here is the part causing the problem:
    PHP Code:
     if ($_REQUEST)
        {
        
    $ProdID $_REQUEST['ProdID']; 
    The trouble is that $_REQUEST may be true without 'ProdID' having been passed as it may be
    true due to the other variable being passed.
    I need to be able to say:
    If $REQUEST contains 'ProdID' (regardless of whether anyother elements are present), then {}
    Thanks in advance
    pete

  2. #2
    vinyl-junkie's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    721

    Re: error when $_POST is not present

    Here is a better way of coding that:

    Code:
    $ProdID = $_REQUEST['ProdID']; 
    
    if ($ProdID = "") {
       //error logic here 
    } else {
      // normal processing
    }
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more

  3. #3
    snowweb's Avatar
    New User

    Status
    Offline
    Join Date
    Jan 2006
    Posts
    7

    Thumbs up Re: error when $_POST is not present

    Quote Originally Posted by vinyl-junkie
    Here is a better way of coding that:

    Code:
    $ProdID = $_REQUEST['ProdID']; 
     
    if ($ProdID = "") {
       //error logic here 
    } else {
      // normal processing
    }
    Thanks. I tried that though and it was saying that there was an error on
    PHP Code:
    $ProdID $_REQUEST['ProdID']; 
    because $_REQUEST['ProdID'] was not present.
    However, I eventually found the solution!
    I used 'isset()' to determine whether the 'ProdID' was passed or not
    Here's how I used it
    PHP Code:
    <?
        
    if (isset($_REQUEST['deleted']))
          { 
             
    $deleted $_REQUEST['deleted']; 
             echo 
    "$deleted";
           }
    ?>
    Thanks for your help.
    peter

  4. #4
    HTML's Avatar
    Administrator

    Status
    Offline
    Join Date
    Aug 2000
    Posts
    3,445

    Follow HTML On Twitter Add HTML on Facebook Add HTML on Google+ Add HTML on Linkedin Visit HTML's Youtube Channel

    Re: error when $_POST is not present

    Thanks for letting us know how you finally solved the problem. I am sure others will find it of help.

    Dave
    AHFBWEB Less customers per server, more power for you!

    Business Class Shared Hosting

  5. #5
    DeadMeatGF's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    381

    Re: error when $_POST is not present

    I tend to use the negative test ...
    PHP Code:
    if (!$_REQUEST['ProdID']) {
       
    //error code goes here
       //exit script if required ...
    }
    $ProdID $_REQUEST['ProdID'];
    //Carry on with the page 



Tags for this Thread