i dont understand the undefind index error in my code.can check for me?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sheau Wei
    New Member
    • Sep 2006
    • 34

    i dont understand the undefind index error in my code.can check for me?

    This is the code the code that i try to run it as my search engine for my database. But i dont understand why i run a notice that undefind index. Can u help me ?

    <form method="post" action="search. php">
    <input type="text" name="search" size=25 maxlength=25>
    <input type="Submit" name="Submit" value="Submit">
    </form>
    <?

    //connect to server
    mysql_pconnect( "localhost","ro ot","password") ;
    //select the db
    mysql_select_db ("school");
    //get the results and store them in $result
    $search=$_POST["search"];

    $result = mysql_query ("SELECT * FROM class WHERE Name LIKE '%$search%'");
    //run the while loop
    while($r=mysql_ fetch_array($re sult))
    {
    //grab the result
    $Name=$r["Name"];
    //print it out
    echo $Name;
    echo "<br>";
    }

    ?>
  • bevort
    New Member
    • Jul 2006
    • 53

    #2
    You get these warning in you error_log file, right?

    PHP does not like undefined vars and indexes. You should get only something like [05-Oct-2006 12:56:33] PHP Notice: Undefined variable: uid in D:\htdocs
    but the code works.

    If you realy want to get rid of them you have to declare all the vars before using them even if they come from a $_POST or $_GET.

    Comment

    • Sheau Wei
      New Member
      • Sep 2006
      • 34

      #3
      Originally posted by bevort
      You get these warning in you error_log file, right?

      PHP does not like undefined vars and indexes. You should get only something like [05-Oct-2006 12:56:33] PHP Notice: Undefined variable: uid in D:\htdocs
      but the code works.

      If you realy want to get rid of them you have to declare all the vars before using them even if they come from a $_POST or $_GET.
      In the code that i had submit, i dont understand how to declare it , can u help me or give me an example? Thanks you

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        On what statement did you get the 'undefined' error message?

        Ronald :cool:

        Comment

        Working...