WEB How do I use submit button?

Discussion in 'OT Technology' started by Otter, Dec 10, 2009.

  1. Otter

    Otter New Member

    Joined:
    Aug 27, 2002
    Messages:
    4,766
    Likes Received:
    0
    If ask too many questions let me know...I'm learning as I go. I am trying to help a small volunteer department out by getting all their run reports online. I threw together a basic little report based on their current one.

    Some things I want to do, but not sure how to do...

    -Make the page only accessible with individual username/password combination
    -When the submit button is clicked, it uses the currently logged in username to "Sign" the report and send it as a .pdf or even a .htm to an email for approval
    -And somehow allow the QA/Supervisor to click a button to give final approval and stamp with currently logged in user.

    Is this possible? or do I need other software...

    here is a very rough example of the report

    www.policeonly.org/report_example.htm
     
  2. brds

    brds OT Supporter

    Joined:
    Jun 26, 2006
    Messages:
    17,689
    Likes Received:
    33
    Location:
    Atlanta
    Totally possible.... 1 sec
     
  3. brds

    brds OT Supporter

    Joined:
    Jun 26, 2006
    Messages:
    17,689
    Likes Received:
    33
    Location:
    Atlanta
    Sign In Script:
    Process.php file:
    From then on, you can put the users username or, with query, you can get their full name.
     
  4. Otter

    Otter New Member

    Joined:
    Aug 27, 2002
    Messages:
    4,766
    Likes Received:
    0
    Forgive me ignorance...

    What does the 2nd script do? and do I just copy and paste into the document?
     
  5. brds

    brds OT Supporter

    Joined:
    Jun 26, 2006
    Messages:
    17,689
    Likes Received:
    33
    Location:
    Atlanta
    Second script takes what the user entered in the form, and compares it against what's in the database. No, you can't just c/p it. You have to first connect to the database and write queries to pull the information.
     
  6. Otter

    Otter New Member

    Joined:
    Aug 27, 2002
    Messages:
    4,766
    Likes Received:
    0
    Man, I guess I am really over my head because I have no idea what that mean...google here i come!
     
  7. brds

    brds OT Supporter

    Joined:
    Jun 26, 2006
    Messages:
    17,689
    Likes Received:
    33
    Location:
    Atlanta
    Okay, the first form simply gets the users username and their password. When you click the submit button, it passes that information along to the process.php file.

    The process.php file looks at the username given to it by the previous page and pull the information about that account from the databases. If the passwords match, it'll sign the user in.
     
  8. Otter

    Otter New Member

    Joined:
    Aug 27, 2002
    Messages:
    4,766
    Likes Received:
    0
    I have that much...I think.

    I logged into my hosting and created a new database and added a couple users. I put the scripts here www.policeonly.org/login.php how do I give the database information to the process.php file and have it forward the user to http://www.policeonly.org/report_example.htm ?
     
    Last edited: Dec 11, 2009
  9. brds

    brds OT Supporter

    Joined:
    Jun 26, 2006
    Messages:
    17,689
    Likes Received:
    33
    Location:
    Atlanta
    for $30, i'll make you a registration page, a login page, and a process page... all you'll have to do is enter your database location, username, password, and name of the DB once I hand the files over. PM me if interested.
     
  10. Otter

    Otter New Member

    Joined:
    Aug 27, 2002
    Messages:
    4,766
    Likes Received:
    0

    I appreciate the offer but I want to learn so I'll just wade through google and ask around. Thanks for your help so far though and I'll keep you in mind if I can't get it in a few days.
     
  11. brds

    brds OT Supporter

    Joined:
    Jun 26, 2006
    Messages:
    17,689
    Likes Received:
    33
    Location:
    Atlanta
    Okay, well here's a skeleton outline of what you should do.

    registration.php:
    Code:
    <form action='processreg.php' method='post'>
    <table>
    
    <tr>
    <td>Username:</td>
    <td><input type='text' name='regusername' /></td>
    </tr>
    
    <tr>
    <td>Password:</td>
    <td><input type='password' name='regpw' /></td>
    </tr>
    
    <tr>
    <td colspan='2'><input type='submit' value='Register &gt;&gt;' /></td>
    </tr>
    
    </table>
    </form>
    

    processreg.php
    Code:
    <?php
    /*Create or download a db connection class and use it... it'll make things much easier... I'll assume you already have a connection to the DB at this point via a class i'll call "connection"*/
    
    if ((strlen($_POST['regusername']) <= 0) || (strlen($_POST['regpw']) <= 0))
    echo "You did not enter in all the require information.  Please <a href='javascript:history.go(-1)'>go back</a> and try again.
    else
    {
    $username = $_POST['regusername'];
    $password = md5($_POST['regpw);
    
    /* Check to see if the username is already in the system */
    if ($connection->runQuery("SELECT * FROM USERS WHERE UPPER(userName) = '" . strtoupper($username) . "'"))
    echo "That username is already taken.  Please <a href='javascript:history.go(-1)'>go back</a> and choose another.
    else
    {
    if ($connection->runQuery("INSERT INTO USERS (userName, password) VALUES ('$username', '$password'))
    {
    $userid = $connection->runQuery("SELECT userID FROM USERS WHERE UPPER(userName) = '" . strtoupper($username) . "'");
    $_SESSION['userid'] = $userid[0]['userID'];
    echo "Your account has been created and you have been signed in.";
    }
    else
    {
    echo "an error has occurred and your account was not created.
    }
    }
    }
    ?>
    
    login.php
    Code:
    <form action='processlogin.php' method='post'>
    <table>
    
    <tr>
    <td>Username:</td>
    <td><input type='text' name='lusername' /></td>
    </tr>
    
    <tr>
    <td>Password:</td>
    <td><input type='password' name='lpw' /></td>
    </tr>
    
    <tr>
    <td colspan='2'><input type='submit' value='Login &gt;&gt;' /></td>
    </tr>
    
    </table>
    </form>
    
    processlogin.php
    Code:
    /* Again, i'm assuming you already have your db connection class up and running */
    
    $password = $connection->runQuery("SELECT password FROM USERS WHERE UPPER(userName) = '" . $_POST['lusername'] . "' LIMIT 1;
    
    if (count($password) == 0)
    echo "username not found";
    else
    {
    $password = md5($password[0]['password']);
    if ($password == md5($_POST['lpw']))
    {
    $userid = $connection->runQuery("SELECT userID FROM USERS where UPPER(userName) = '" . strtoupper($_POST['lusername']) . "' LIMIT 1;");
    $_SESSION['userid'] = $userid[0]['userID'];
    echo "You are now logged in!";
    }
    else
    {
    echo "Bad information given.";
    }
    }
    
    something like that should do the trick... i didn't proof the code, so there might be some syntax errors in there... but you get the idea (i hope)
     
  12. Ricky

    Ricky █▄ █▄█ █▄ ▀█▄

    Joined:
    Jun 17, 2005
    Messages:
    38,763
    Likes Received:
    6
    some things i should point out since you seem kind of new

    1) dont use ms office. i noticed that you used that for your example. Learn html, how to code with notepad etc. w3school or wahtever is a great website.

    2) You'll need to learn how to create a database/user for mysql. It's pretty simple for some of us, but i figure for a person just starting out it can be pretty intimidating. Just google tutorials and you'll get it. You'll just have to plug in your login info and such into the script brd made.

    3) learn php. Im still in the process of learning myself, but after awhile you slowly get the idea of things and start to understand how the structure should be. If you learn the php, you'll be able to manipulate and add/remove components to brds script.
    Good luck
     
  13. Otter

    Otter New Member

    Joined:
    Aug 27, 2002
    Messages:
    4,766
    Likes Received:
    0
    correct..I am brand spanking new...seems like a hige learning curve...but I'll get it..eventually I hope
     
  14. Otter

    Otter New Member

    Joined:
    Aug 27, 2002
    Messages:
    4,766
    Likes Received:
    0
    so now what is wrong...I get this:
    Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'user'@'174.120.195.58' (using password: YES) in /home/sharptj/public_html/registration1.php on line 3
    Access denied for user 'user'@'174.120.195.58' (using password: YES)

    Code:
    <?php
    // Connects to your Database
    mysql_connect("www.policeonly.org", "user", "password") or die(mysql_error());
    mysql_select_db("sharptj_kvers") or die(mysql_error());
    
    //This code runs if the form has been submitted
    if (isset($_POST['submit'])) {
    
    //This makes sure they did not leave any fields blank
    if (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] ) {
    die('You did not complete all of the required fields');
    }
    
    // checks if the username is in use
    if (!get_magic_quotes_gpc()) {
    $_POST['username'] = addslashes($_POST['username']);
    }
    $usercheck = $_POST['username'];
    $check = mysql_query("SELECT username FROM users WHERE username = '$usercheck'")
    or die(mysql_error());
    $check2 = mysql_num_rows($check);
    
    //if the name exists it gives an error
    if ($check2 != 0) {
    die('Sorry, the username '.$_POST['username'].' is already in use.');
    }
    
    // this makes sure both passwords entered match
    if ($_POST['pass'] != $_POST['pass2']) {
    die('Your passwords did not match. ');
    }
    
    // here we encrypt the password and add slashes if needed
    $_POST['pass'] = md5($_POST['pass']);
    if (!get_magic_quotes_gpc()) {
    $_POST['pass'] = addslashes($_POST['pass']);
    $_POST['username'] = addslashes($_POST['username']);
    }
    
    // now we insert it into the database
    $insert = "INSERT INTO users (username, password)
    VALUES ('".$_POST['username']."', '".$_POST['pass']."')";
    $add_member = mysql_query($insert);
    ?>
    
    
    <h1>Registered</h1>
    <p>Thank you, you have registered - you may now login</a>.</p>
    <?php
    }
    else
    {
    ?>
    
    
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <table border="0">
    <tr><td>Username:</td><td>
    <input type="text" name="username" maxlength="60">
    </td></tr>
    <tr><td>Password:</td><td>
    <input type="password" name="pass" maxlength="10">
    </td></tr>
    <tr><td>Confirm Password:</td><td>
    <input type="password" name="pass2" maxlength="10">
    </td></tr>
    <tr><th colspan=2><input type="submit" name="submit" value="Register"></th></tr> </table>
    </form>
    
    <?php
    }
    ?>
     
  15. Ricky

    Ricky █▄ █▄█ █▄ ▀█▄

    Joined:
    Jun 17, 2005
    Messages:
    38,763
    Likes Received:
    6
    it cant conect to the database.

    are you sure the login info is correct?... username=user... password=pass?

    also try changing poiliceonly to localhost

    also does the user "user" have the correct permission to view/delete/add rows etc for that database ? you might want to check that out in phpmyadmin or rwahtever you're using
     
  16. Otter

    Otter New Member

    Joined:
    Aug 27, 2002
    Messages:
    4,766
    Likes Received:
    0
    yeah i am usung phpmyadmin and user has all access, with the correct password...should the database be sharptj_KVERS or just KVERS?
     
  17. Ricky

    Ricky █▄ █▄█ █▄ ▀█▄

    Joined:
    Jun 17, 2005
    Messages:
    38,763
    Likes Received:
    6
    okays lets break it down a little. this will help you understand the basics and troubleshoot the problem.

    <?php
    mysql_connect("localhost", "user", "pass") or die(mysql_error());
    echo "Connected to MySQL<br />";
    mysql_select_db("sharptj_KVERS ") or die(mysql_error());
    echo "Connected to Database";
    ?>

    now if sharptj whatever doesnt connect, plug in the other one. that'll give you your anwser and help you figure out the problem.
     
  18. Otter

    Otter New Member

    Joined:
    Aug 27, 2002
    Messages:
    4,766
    Likes Received:
    0
    lol..I did both...it must be something simple...I guess I will go to bed and look at it tommorow with fresh eyes (and brain)

    I would have thought submit button would have been easy...I thought wrong, but I am learing alot so thats cool.
     
  19. Ricky

    Ricky █▄ █▄█ █▄ ▀█▄

    Joined:
    Jun 17, 2005
    Messages:
    38,763
    Likes Received:
    6
    did both fail?

    if so, you might be using a shared server or some shit, with a dedicated sql box.. so you cant exactly use localhost. most of the time the host has a little note in their FAQ which lets you know what to use instead of localhost.
     
  20. Otter

    Otter New Member

    Joined:
    Aug 27, 2002
    Messages:
    4,766
    Likes Received:
    0
    ok thanks...i'll look for the faq

    i got it..but now the next page is messed up...of well...for another day
     
    Last edited: Dec 14, 2009

Share This Page