Notice: Undefined index: name in C:\wamp\www\xxx\job_preview.php on line

Discussion in 'PHP' started by bokivaol, Sep 19, 2010.

  1. #1
    Hi.
    I use WampServer Version 2.0 and when I tried to execute this script I got an error:


    Notice: Undefined index: name in C:\wamp\www\xxx\job_preview.php on line 8

    Notice: Undefined index: name in C:\wamp\www\xxx\job_preview.php on line 17

    Notice: Undefined variable: normal_price in C:\wamp\www\xxx\job_preview.php on line 23

    8    if($_REQUEST["name"]!="")
    9    {
    10    $Title=$_REQUEST["name"];
    11    }
    12    else
    13    {
    14    $Title=$_REQUEST["Title"];
    15    }
    16        
    17    if($_REQUEST["name"]!="")
    18    {
    19    $highlight=$extra_price;
    20    }
    21    else
    22    {
    23    $highlight=$normal_price;
    24    }
    25    $wd2=(addslashes($_POST["Available_positions"]));
    26 ?>    
    PHP:
    Can anyone help me to solve this problem?
     
    bokivaol, Sep 19, 2010 IP
  2. nabil_kadimi

    nabil_kadimi Well-Known Member

    Messages:
    1,065
    Likes Received:
    69
    Best Answers:
    0
    Trophy Points:
    195
    #2
    Hello,

    Those are errors of type "E_NOTICE", it's a good practice to show them if you are developing but they should be hidden from public.

    From this point you have 2 choices:
    1 - Correct those minor errors
    2 - Hide and ignore them

    ------
    1 -
    replace
    if($_REQUEST["name"]!="")
    PHP:
    with
    if(isset($_REQUEST["name"]) && $_REQUEST["name"]!="")
    PHP:
    ------
    2 -
    In your PHP configuration file (php.ini) set "error_reporting like this:
    error_reporting = E_ALL & ~E_NOTICE 
    Code (markup):
    ------
    Resource: http://www.php.net/manual/en/errorfunc.configuration.php#ini.error-reporting
     
    nabil_kadimi, Sep 19, 2010 IP
  3. bokivaol

    bokivaol Greenhorn

    Messages:
    66
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    18
    #3
    Thank you a lot. I have already solved it on the 2nd way, but I would like to solve it in the code. As you said I solved lines 8 and 17 with replacing, but I still have a problem with line 23. What to do with line 23? Thank you again.
     
    bokivaol, Sep 19, 2010 IP
  4. nabil_kadimi

    nabil_kadimi Well-Known Member

    Messages:
    1,065
    Likes Received:
    69
    Best Answers:
    0
    Trophy Points:
    195
    #4
    Could you please post the error message
     
    nabil_kadimi, Sep 19, 2010 IP
  5. bokivaol

    bokivaol Greenhorn

    Messages:
    66
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    18
    #5

    Notice: Undefined variable: normal_price in C:\wamp\www\xxx\job_preview.php on line 23
     
    bokivaol, Sep 19, 2010 IP
  6. nabil_kadimi

    nabil_kadimi Well-Known Member

    Messages:
    1,065
    Likes Received:
    69
    Best Answers:
    0
    Trophy Points:
    195
    #6
    Try to understand PHP's error messages:
    You're telling PHP to assign a value which he doesn't know (because it has not been set in the previous lines of code)
    this will suppress the error but may bring newer error (depending on how you wrote your code).

    if(isset($normal_price)) $highlight=$normal_price;
    PHP:
    I guess this is not what you want to do, at line 23 $normal_price should already have been set
     
    nabil_kadimi, Sep 19, 2010 IP
  7. bokivaol

    bokivaol Greenhorn

    Messages:
    66
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    18
    #7
    Thank you!
     
    bokivaol, Sep 19, 2010 IP