Results 1 to 10 of 10
  1. #1
    Join Date
    Nov 2005
    Posts
    40

    Unanswered: Undefined VAriable !!!

    In a search form with one button Search and one Field when i try to run the php file it always tells me "UNDEFINED VARIABLE".I have 2 variables(search area and list selection) and i think there is no problem with their definition.

    Is there possible that PHP has been installed false?What is wrong?

  2. #2
    Join Date
    Apr 2005
    Location
    Baltimore, MD
    Posts
    297
    post your code and errors.

  3. #3
    Join Date
    Jan 2004
    Location
    India
    Posts
    168
    Hi
    The error you are saying is just a warning. You can avoid this by defining the variable.
    eg:
    $a=0; // $a is an integer
    $b="" // $b is a string

    Else you can just avoid that notice warning by editing the php.ini file.
    You need to uncomment this line
    error_reporting = E_ALL & ~E_NOTICE
    This indicates that the messages will be given for all errors but no notice or warnings.

    If you problem doesn't solve please post in you code.

    Regards
    Rajesh
    Freelance and Technology Consultant
    -------------------
    Dreams are for ever
    -------------------

  4. #4
    Join Date
    Nov 2005
    Posts
    40

    ????????

    I have a very simple page with the code :

    <form action="res.php" method="post">
    Choose Search Type:<br>
    <select name="searchtype">
    <option value="name">Name
    <option value="title">Title
    </select>
    <br>
    Enter Search Term:<br>
    <input name="searchterm" type=text>
    <br>
    <input type=submit value="Search">
    </form>
    and the res.php when i press the button search :
    .....

    if (!$searchtype || !$searchterm)
    {
    echo "You have not entered search details. Please go back and try again.";
    exit;
    }

    .....
    why it tells me that $searchtype and $searchtemr are undefined variables?????? Is there a mistake in PHP or IIS installation ?????

  5. #5
    Join Date
    Apr 2005
    Location
    Baltimore, MD
    Posts
    297
    use $_POST['searchtype'] and $_POST['searchterm']

  6. #6
    Join Date
    Apr 2005
    Location
    Baltimore, MD
    Posts
    297
    and also using the ! operator is probably not what you want to be doing here.

  7. #7
    Join Date
    Jan 2004
    Location
    India
    Posts
    168
    Quote Originally Posted by archVille
    I have a very simple page with the code :

    <form action="res.php" method="post">
    Choose Search Type:<br>
    <select name="searchtype">
    <option value="name">Name
    <option value="title">Title
    </select>
    <br>
    Enter Search Term:<br>
    <input name="searchterm" type=text>
    <br>
    <input type=submit value="Search">
    </form>
    and the res.php when i press the button search :
    .....

    if (!$searchtype || !$searchterm)
    {
    echo "You have not entered search details. Please go back and try again.";
    exit;
    }

    .....
    why it tells me that $searchtype and $searchtemr are undefined variables?????? Is there a mistake in PHP or IIS installation ?????
    Use $_POST['searchtype'] and $_POST['searchterm']. And instead of checking it using <b>!</b> use isset($_POST['searchterm'])) and isset($_POST['searchtype'])

    Me me know if it works for you.

    Rajesh
    Freelance and Technology Consultant
    -------------------
    Dreams are for ever
    -------------------

  8. #8
    Join Date
    Nov 2005
    Posts
    40
    Thanx , the $_POST function worked!

    Why couldnt the other way to handle variables ???An older version of php ?

  9. #9
    Join Date
    Apr 2005
    Location
    Baltimore, MD
    Posts
    297
    Nope, that just how you access form parameters in php. They are stored in array variables. You'll use either the $_POST, $_GET, or $_REQUEST. There are a few useful variables like this. Check out http://us2.php.net/reserved.variables

  10. #10
    Join Date
    Jan 2004
    Location
    India
    Posts
    168
    If you eneable global variable on in you php.ini you can use the variable directly with out even using $_POST or such arrays, but it is not recomanded as the securtiy in this is lower.

    Regards
    Rajesh
    Freelance and Technology Consultant
    -------------------
    Dreams are for ever
    -------------------

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •