php notice: undefined variable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • prabhunew2005
    New Member
    • Aug 2006
    • 10

    #1

    php notice: undefined variable

    hi

    I am doing web portal design using php.
    I gave part of one of my screen coding.

    <html>
    <head>
    <script language = "javascript ">

    function list_all_click( )
    {
    search_by_index _value = 0;
    jb_asc_desc_ord er = "A";


    document.locati on = "jukeboxes.php? search_by_value ="+search_by_in dex_value+"&jb_ asc_desc_order_ val="+jb_asc_de sc_order;

    }

    </script>
    <head>
    </html>

    <body>

    <?php

    @extract($_GET) ;
    @extract($_POST );

    if($search_by_v alue == "")
    $search_by_valu e = 0;

    if($jb_asc_desc _order_val == "D")
    {
    $order_by_strin g1 = "jukeboxes" ;
    $order_by_strin g2 = "jukebox_serial ";
    $order = "desc";
    }
    ?>

    <table>
    <tr>
    <td><img src="images/list.jpg" alt="Click to list All Jukebox" width="50" height="13" align="absmiddl e" onclick = "list_all_click ()"></td>
    </tr>
    </table>

    </body>

    The above code is presented in 'jukeboxes.php' file that is variables are passed to the self php page through javascript.
    It is working functionwise properly. I am getting expected output in the screen.
    But the problem is that the following two warning messages is written in system 'error log' file.
    message1:
    "
    [client 125.17.100.148] PHP Notice: Undefined variable: search_by_value in /var/www/html/dco/jukeboxes.php on line 362, referer: http://125.17.100.148/dco/company.php
    "
    Where the line 362 is
    'if($search_by_ value == "")'


    message2:
    "
    [client 125.17.100.148] PHP Notice: Undefined variable: jb_asc_desc_ord er_val in /var/www/html/dco/jukeboxes.php on line 766, referer: http://125.17.100.148/dco/jukeboxes.php
    "
    Where the line 766 is
    'if($jb_asc_des c_order_val == "D")'

    The system has linux operating system.
    I need to solve the problem as soon as possible.

    Please help me.
    Advance thanks.

    regards
    N.Prabhu
    Last edited by prabhunew2005; Sep 18 '06, 08:55 AM. Reason: for giving extra information
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    If you just load the page with nothing on the URL after the ? then

    $search_by_valu e
    $jb_asc_desc_or der_val

    are not defined by the extract functions.

    These are only information messages and could be ignored but to get rid of them change

    [php]

    if($search_by_v alue == "")
    $search_by_valu e = 0;


    if($jb_asc_desc _order_val == "D")
    {
    $order_by_strin g1 = "jukeboxes" ;
    $order_by_strin g2 = "jukebox_serial ";
    $order = "desc";
    }
    [/php]

    respectively to

    [php]

    if(!isset($sear ch_by_value) || $search_by_valu e == "")
    $search_by_valu e = 0;


    if(isset($jb_as c_desc_order_va l) && $jb_asc_desc_or der_val == "D")
    {
    $order_by_strin g1 = "jukeboxes" ;
    $order_by_strin g2 = "jukebox_serial ";
    $order = "desc";
    }
    else
    {
    /* Different values */
    }
    [/php]

    isset is a function (well inbuilt operator really) that tests to see if a variable has been defined.

    Comment

    Working...