The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Undefined index error

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
  • #27051

    I recently moved web hosts – previously I had no problems with the PHP but now I’m getting two errors.

    The first:

    Notice: Undefined index: email in on line 21

    Heres The Code:

    if ($_POST) {
    //Connect to the database through our include
    include_once "connect_to_mysql.php";
    $email = stripslashes($_POST);
    $email = strip_tags($email);
    $email = mysql_real_escape_string($email);
    $password = ereg_replace("[^A-Za-z0-9]", "", $_POST); // filter everything but numbers and letters
    $password = md5($password);
    // Make query and then register all database data that -
    // cannot be changed by member into SESSION variables.
    // Data that you want member to be able to change -
    // should never be set into a SESSION variable.
    $sql = mysql_query("SELECT * FROM members WHERE email='$email' AND password='$password' AND emailactivated='1'");
    $login_check = mysql_num_rows($sql);
    if($login_check > 0){
    while($row = mysql_fetch_array($sql)){
    // Get member ID into a session variable
    $id = $row["id"];
    $_SESSION = $id;
    // Get member username into a session variable
    $username = $row["username"];
    $_SESSION = $username;
    // Update last_log_date field for this member now
    mysql_query("UPDATE members SET lastlogin=now() WHERE id='$id'");
    // Print success message here if all went well then exit the script
    header("location: member_profile.php?id=$id");
    } // close while
    } else {
    // Print login failure message to the user and link them back to your login page
    print '

    No match in our records, try again

    Click here to go back to the login page.';
    }// close if post

    The second is after I login I get this error:

    Notice: Undefined index: username in on line 9

    Heres the code:

    session_start(); // Must start session first thing

    // See if they are a logged in member by checking Session data
    $toplinks = "";
    if (isset($_SESSION)) {
    // Put stored session variables into local php variable
    $userid = $_SESSION;
    $username = $_SESSION;
    $barstatus1 = 'My Account';
    $barstatus2 = 'Log Out';
    $econsult = 'e-Consultation';
    $toplinks = '
  • My Account

  • Log Out
  • ';
    $econsult_links = '
  • Lumps and Bumps

  • Mole Check

  • Skin Rashes
  • ';
    } else {
    $barstatus1 = 'Login';
    $barstatus2 = 'Register';
    $econsult = 'e-Consultation';
    $toplinks = '
  • Login

  • Register
  • ';
    $econsult_links = '
  • Lumps and Bumps

  • Mole Check

  • Skin Rashes
  • ';

    Basically it’s saying theres undefined index’s but I’m pretty sure they are defined in the code as this exact script was working before.

    Could someone help please?


    the first error causes the second one in my opinion. since a user to a non-given email cannot be found. does “var_dump($_POST)” say email is given? what does the login-form look like?


    login form >

    also getting undefined index on registration form fields


    these are only notices, so the code can still run i think. Your other server with your previous host probably had error reporting off. Now in your new environment the error reporting is on so the notices and warnings show up.

    Of course if is better to fix the problems then simply turning off error reporting as the errors and notices are still generated but not displayed so it has a performance hit on your website (although probably a small one).


    hey ralc thanks for that. Yeah everyone still seems to be working fine. How do I turn these error messages off? any ideas?

Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘Back End’ is closed to new topics and replies.