Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Mar 2012
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts

    error in user form

    Hi I am getting this error when I tried and run this coding for a user form I am new to this and need help been messing with this all morning trying to fix the errror nothing I do fixes it.
    ( ! ) Notice: Undefined index: myusername in C:\wamp\www\check_login.php on line 15
    Call Stack
    # Time Memory Function Location
    1 0.0005 374288 {main}( ) ..\check_login.php:0

    ( ! ) Notice: Undefined index: mypassword in C:\wamp\www\check_login.php on line 16
    Call Stack
    PHP Code:
    <?php
    $host
    ="localhost"// Host name
    $username="user1"// Mysql username
    $password="password1"// Mysql password
    $db_name="test_db"// Database name
    $tbl_name="test"// Table name

    // Connect to server and select database.
    mysql_connect("$host""$username""$password")or
    die(
    "cannot connect");
    mysql_select_db("$db_name")or die("cannot select DB");

    // username and password sent from form
    session_start();
    $myusername=$_POST['myusername'];
    $mypassword=$_POST['mypassword'];

    // To protect MySQL injection (more detail about MySQL injection)
    $myusername stripslashes($myusername);
    $mypassword stripslashes($mypassword);
    $myusername mysql_real_escape_string($myusername);
    $mypassword mysql_real_escape_string($mypassword);

    $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and 
    password='$mypassword'"
    ;
    $result=mysql_query($sql);

    $count=mysql_num_rows($result);

    if(
    $count==1){
    $_SESSION['myusername'] = $myusername;        
    $_SESSION['mypassword'] = $mypassword;    // after succesfully register the username & password we go to login_success.php    header("location:login_success.php");
    }
    else{echo
    " Invalid Username or Password";
    }
    ?>
    heres the form that follows
    PHP Code:
    <?
    session_start
    ();
    if ( !isset(
    $_SESSION['myusername']) )
    {  
    header("location:main_login.php");
    }
    ?>
    <html>
    <body>
    <?php$myusername $_SESSION['myusername'];
    print 
    "Welcome $_SESSION[myusername] \n";
    print 
    "Welcome $myusername \n";?>
    Login Successful
    </body>
    </html>

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    This is the wrong forum, moving to PHP.
    PHP Code:
    $myusername=$_POST['myusername'];
    $mypassword=$_POST['mypassword']; 
    There is no valid post data called myusername or mypassword. Verify the form is using the correct names for the inputs and the method is set to post.
    This should be validated and never run unless fields are provided. All of this could (except maybe the config variables if you want) should be wrapped:
    PHP Code:
    if (isset($_POST['myusername'], $_POST['mypassword']))
    {
        
    // do your stuff here



  •  

    Posting Permissions

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