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 5 of 5

Thread: php problem

  1. #1
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    php problem

    alright this is my login system(it is working ok) here but the problem i am having is that i want to add user_id and user_password to my database from my webpage and these user_id and user_passwords would be used to login to the system


    login.php

    Code:
    session_start();
    
    $errorMessage = '';
    if (isset($_POST['txtUserId']) && isset($_POST['txtPassword'])) {
        include 'config.php';
        include 'opendb.php';
    
        $userId   = $_POST['txtUserId'];
        $password = $_POST['txtPassword'];
    
        // check if the user id and password combination exist in database
        $sql = "SELECT user_id
                FROM tbl_auth_user
                WHERE user_id = '$userId' AND user_password =MD5('$password')";
    
        $result = mysql_query($sql) or die('Query failed. ' . mysql_error());
    
        if (mysql_num_rows($result) == 1) {
            // the user id and password match,
            // set the session
            $_SESSION['db_is_logged_in'] = true;
    
            // after login we move to the main page
            header('Location:);
            exit;
        } else {
            $errorMessage = 'Sorry, wrong user id / password';
        }
    
    
    }
    ?>
    <html>
    <head>
    <title>Basic Login</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    
    <body>
    <?php
    if ($errorMessage != '') {
    ?>
    
    
    
    ive tried this with no suucess
    
    insertdata.html
    
    
    
    <html>
      <head>
        <title>Admin section</title>
      </head>
      <body>
    
    
    
        <h1>Add a student </h1>
        <form method="post" action="">
          <p> please enter your  student password and e-mail address below.</p>
          <p>
            Please enter student email address:
            <br>
            <input type="text" name="user_id" size="35">
            <br>
            Please enter student  password:
    		<br>
    		 <input type="text" name="user_password" size="35">
    
    <br>
          </p>
          <input type="submit" value="Add address">
          <input type="reset" value="start over">
        </form>
    
    <br>
        <HR>
    <br>
    
    
    insertdata.php
    
    
    <html>
      <head>
        <title>Return Page</title>
      </head>
      <body>
        <h1>Thank you for filling out my form!</h1>
        <?php
          $link_id = mysql_connect('', '', '') or die ("Could not connect: " . mysql_error());
    
    
    
          mysql_select_db("", $link_id);
    
    
          $user_id = addslashes($user_id);    // addslashes() escapes any characters that
                                        // could confuse MySQL, i.e. ',`,", etc.
          $user_password = addslashes($user_password);
    
    
          $insert_sql = "INSERT INTO tbl_auth_user (user_id, user_password) VALUES ('$user_id', '$user_password')";
          mysql_query($insert_sql, $link_id) or die ("Insert failed: " . mysql_error());
          mysql_close($link_id);
        ?>
    
        <p>Thank you, <?php echo $user_id ?>, was added to the database!</p>
    database



    CREATE TABLE tbl_auth_user (
    user_id VARCHAR(10) NOT NULL,
    user_password CHAR(32) NOT NULL,
    PRIMARY KEY (user_id)
    );

    INSERT INTO tbl_auth_user (user_id, user_password) VALUES ('theadmin', MD5('chumbawamba'));
    INSERT INTO tbl_auth_user (user_id, user_password) VALUES ('webmaster', MD5('webmistress'));



    ANY HELP WOULD BE MUCH APPRECIATED THANK YOU IN ADVANCE
    Last edited by fergie223; 08-22-2006 at 09:15 PM.

  • #2
    New Coder
    Join Date
    Jul 2006
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What is the exact problem that you are having? What is the error? What is not working correctly?

  • #3
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts

    More descriptive subject

    In the future, please use a more descriptive subject when posting a question. See posting guidelines.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #4
    New Coder
    Join Date
    Aug 2006
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    He wants a register option basically.

  • #5
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    sorry bout topic description. the problem i am having is that the user_id and user_password are being entered into the database using insertdata.php but when i try to use these in the login system they dont work. i think it may have something to do with MD5. thanks again


  •  

    Posting Permissions

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