SitePoint Sponsor

User Tag List

Results 1 to 24 of 24
  1. #1
    SitePoint Addict
    Join Date
    Jun 2007
    Location
    Plymouth uk
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Please help cant get this login code to work

    ok i have a login form and logon and edit forms
    you login and then takes you to edit screen which is suppose to show details from database
    but it tells me logged in success but the edit page is blank
    any help please

    login code
    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>login</title>
    </head>

    <body>
    <?php include("menu_u.php");

     
    ?>
        Members Login<br> 
           <form action="test-logon.php" method="POST"> 
           
           Username:<input type="username" name="username"> 
           
           Password:<input type="password" name="password"> 
           
           <input type="submit" name="submit" value="submit this"> 
           </form> 
        
    </body>
    </html>
    logon code
    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>logon</title>
    </head>

    <body>
    <?php
    function authenticate($username$password){ 
        

        
    $request "SELECT * FROM members WHERE password=('$password') AND username='$username'"

        
    // Pass the request to the mysql connection, 

        
    $results query_db($request); 

        
    // if mysql returns any number of rows great than 0 there is a match 
        
    return $results


    function 
    query_db($query){ 
        
    $conn =$dbh=mysql_connect("localhost""car""57"); 
        if (!
    $conn) { 
            die(
    'Could not connecteeer: ' mysql_error()); 
        } 
        
    mysql_select_db("car"); 
        
    $results mysql_query($query$conn); 
        
    mysql_close($conn); 


        return 
    $results




       
    $form 
       <p align="center" class="bodytext">
        Members Login<br> 
           <form action="test-edit.php" method="post"> 
           
           Username:<input type="name" name="username"> 
           
           Password:<input type="password" name="password"> 
           
           <input type="submit" name="submit" value="submit this"> 
           </form> 
           '


    if(isset(
    $_POST['submit'])){ 

        
    $login $_POST['username'] ;
        
    $password $_POST['password'] ;    
        
    $hm authenticate($login $password); 
        
    $hm2 mysql_num_rows($hm); 
        if(
    $hm2 0){ 
        
    setcookie("Caravan"$login);
          echo 
    "You have successfully Logged in! You will be redirected in three seconds!><br /><br />
                    
                    <div class='info'>If you don't wish to wait, <a href='test-edit.php'>click here</a>"
    ;
                    
                    echo
    '<meta http-equiv="REFRESH" content="1;url=test-edit.php">';
        }else{ 
          echo 
    "username / password not valid<br>"
          echo 
    $form
        } 

    }else{ 
        echo 
    $form



     
    ?>
     
    </body>
    </html>
    edit code

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Edit</title>
    </head>

    <body>
    <?php
    if($_POST['action'] == "edit") {

    //This gets all the other information from the form
    $region=$_POST['region']; 
    $name=$_POST['name'];
    $username=$_POST['username'];
    $password=$_POST['password'];
    $email=$_POST['email'];
    $contact=$_POST['contact'];
    $parkname=$_POST['parkname'];
    $county=$_POST['county'];
    $parklocation=$_POST['parklocation'];
    $make=$_POST['make'];
    $caravandetails=$_POST['caravandetails'];
    $smoke=$_POST['smoke'];
    $pets=$_POST['pets'];
    $kids=$_POST['kids'];
    $sex=$_POST['sex'];

    // Connects to your Database 
    $dbh=mysql_connect("localhost""car""57") or die ('Cannot connect to the database because: ' mysql_error());

    mysql_select_db("car");
     
    //Writes the information to the database 
    mysql_query("UPDATE members SET region=\"$region\", name=\"$name\", username=\"$username\", password=\"$password\", email=\"$email\", contact=\"$contact\" , parkname=\"$parkname\" , county=\"$county\", parklocation=\"$parklocation\",   make=\"$make\", caravandetails=\"$caravandetails\", smoke=\"$smoke\", pets=\"$pets\", kids=\"$kids\", sex=\"$sex\", pname=\"$pname\", enq=\"$enq\" WHERE username =\"$username\" ");
     

    echo 
    "Success! Your information has been Updated. PleaseWait till you are redirected to the homepage.";
                        echo
    '<meta http-equiv="REFRESH" content="2;url=logout.php">';
                        
     }
    else {

       
    $hm authenticate($_COOKIE['Caravan']);
      
    $hm2 mysql_num_rows($hm); 

    if (
    $hm2 0


    $dbh=mysql_connect("localhost""car""57") or die ('Cannot connect to the database because: ' mysql_error());
    mysql_select_db("car");

    $sql "SELECT * FROM members WHERE username ='$_COOKIE[Caravan]'";

    $result mysql_query($sql,$dbh) or die("Couldn't execute profile query.");
    $num=mysql_num_rows($result);

    while (
    $row mysql_fetch_array($result)) {
    extract($row);
    }


    ?>
    <form name="form" onsubmit="return ValidateRequiredFields();" action="<?echo $PHP_SELF ?>" method="POST">
    <div id="info" style="width:360px;">

        <div align="left">
               <strong>Edit Your Listing</strong><br>
          <br />
       <strong>Type:</strong>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
       <select name="region" value=<? echo $region ?>>
            <option value="HIRE">4 Hire</option>
            <option value="EXCHANGE">Exchange</option>
            <option value="EXCHANGE/HIRE">Exchange and Hire</option>
            </select> <br>
          <br />
          <input name="name" type="text" value="<? echo $name ?>"> 
          <strong>Name:</strong>    <br>
          <br />
          <input type="text" name="username" value=<? echo $username ?>
          <strong>Username:</strong>    <br>
          <br />
          <input name="password" type="password" value=<? echo $password ?>
          <strong>Password:</strong>    <br> 
          <br />
          <input type="text" name = "email" value=<? echo $email ?>
          <strong>Email: </strong><br>
          <br />
          <input type="text" name = "contact" value="<? echo $contact ?>">
          <strong>Tel Number:</strong> <br>
          <br />
          <input type="text" name="parkname"  value="<? echo $parkname ?>"> 
          <strong>Park Name:</strong>    <br>
          <br />
          <strong>Select County: </strong> 
          <select name="county" value=<? echo $county ?>>
      <Option VALUE="South West">South West</option>
      <Option VALUE="South East">South East</option>
      <Option VALUE="Wales">Wales</option>
      <option value="Scotland">Scotland</option>
      <option value="London">London</option>
      <option value="East England">East of England</option>
      <option value="West Midlands">West Midlands</option>
      <option value="East Midlands">East Midlands</option>
      <option value="Yorkshire">Yorkshire & Humberside</option>
      <option value="Northwest">North West</option>
      <option value="Northeast">North East</option>
      <option value="Other">Other</option>
            </select> <br>
            <br/>
          <input type="text" name="parklocation" value="<? echo $parklocation ?>"> 
          <strong>Park Location:</strong> <br>
          <br />
          <input type="text" name="make" value="<? echo $make ?>">
          <strong>Make and Model</strong><br>
          <br/>
          <strong>Caravan Details:</strong><br>      
          <textarea name="caravandetails" cols="40" rows="5"> <? echo $caravandetails?> </textarea><br> 
          <br/>
          <input type="text" name="smoke" value="<? echo $smoke ?>">
          <strong>Smoking Allowed</strong><br>
          <br/>
          <input type="text" name="pets" value="<? echo $pets ?>">
          <strong>Pets Allowed</strong><br>
          <br/>
          <input type="text" name="kids" value="<? echo $kids ?>">
          <strong>Children Allowed</strong><br>
          <br/>
          <input type="text" name="sex" value="<? echo $sex ?>">
          <strong>Same Group Sex Allowed</strong><br>
          <br/>
           <input type="hidden" name="action" value="edit"></div>
          <input type="submit" value="Edit Details"/> 
        
    </form>
    <? }

    else
    {
    echo 
    "You must login to do that. <a href=test-login.php>Click here</a>";
    }



     } 
    ?>
    </body>
    </html>
    an old man of 60 trying to keep up with the youngsters he he
    http://lostpetsplymouth.net16.net

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    When you say blank page, do you mean totally blank white page? If so it sounds like there is either a fatal error or parse error somewhere in the edit page and you have error reporting turned off.

    add the following code to the top of edit page
    PHP Code:
    ini_set("display_errors"2);
    ERROR_REPORTING(E_ALL); 
    and see if it gives any error messages.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    SitePoint Addict
    Join Date
    Jun 2007
    Location
    Plymouth uk
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is what i get
    Notice: Undefined index: action in /home/caravanh/public_html/test/test-edit.php on line 13

    Fatal error: Call to undefined function authenticate() in /home/caravanh/public_html/test/test-edit.php on line 47

    line 13 is
    PHP Code:
    if($_POST['action'] == "edit") { 
    and line 47 is
    PHP Code:
    $hm authenticate($_COOKIE['Caravan']); 
    cheers
    Doug
    an old man of 60 trying to keep up with the youngsters he he
    http://lostpetsplymouth.net16.net

  4. #4
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    OK, what that means it that it cant find the function authenticate() on that page because it isnt on that page!

    What you can do is to put your functions on a separate page and include them into your scripts eg:

    functions.php
    PHP Code:
    function authenticate($username$password){ 
        
    $request "SELECT * FROM members WHERE password=('$password') AND username='$username'"
        
    // Pass the request to the mysql connection, 
        
    $results query_db($request); 

       
    // if mysql returns any number of rows great than 0 there is a match 
       
    return $results


    function 
    query_db($query){ 
        
    $conn =$dbh=mysql_connect("localhost""car""57"); 
        if (!
    $conn) { 
            die(
    'Could not connecteeer: ' mysql_error()); 
        } 
        
    mysql_select_db("car"); 
        
    $results mysql_query($query$conn); 
        
    mysql_close($conn); 


        return 
    $results

    and then on your pages: (eg edit)
    PHP Code:
    <?php include('functions.php'); ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Edit</title>
    </head>

    <body>
    // etc
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  5. #5
    SitePoint Addict
    Join Date
    Jun 2007
    Location
    Plymouth uk
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok getting some where what happens now
    keeps coming back to login page
    if you want to try it is
    www.djbcaravanhire.co.uk/test/test-login/
    name tracy pass static
    cheers
    Doug
    an old man of 60 trying to keep up with the youngsters he he
    http://lostpetsplymouth.net16.net

  6. #6
    SitePoint Addict
    Join Date
    Jun 2007
    Location
    Plymouth uk
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is result of test
    Notice: Undefined index: action in /home/caravanh/public_html/test/test-edit.php on line 13

    Warning: Missing argument 2 for authenticate(), called in /home/caravanh/public_html/test/test-edit.php on line 47 and defined in /home/caravanh/public_html/test/functions.php on line 10

    Notice: Undefined variable: password in /home/caravanh/public_html/test/functions.php on line 11
    cheers
    Doug
    an old man of 60 trying to keep up with the youngsters he he
    http://lostpetsplymouth.net16.net

  7. #7
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Hi Doug

    the Authenticate function expects 2 parameters or arguments to be sent to it.
    On TestEdit you have only given it 1 - the COOKIE variable.

    This is fine as long as you tell the function that the arguments can be null/missing by declaring it

    PHP Code:
    authenticate($username$password=null) {
    //

    The null makes the $password variable optional.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  8. #8
    SitePoint Addict
    Join Date
    Jun 2007
    Location
    Plymouth uk
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks Spike for all your help
    but i am going from bad to worse getting all mixed up with all these files
    think i should start again with some thing smaller get that to work and then alter as needed
    i have downloaded a login script which only uses 1 page which seems to work ok
    its still the editing bit that dosnt work
    also should i use 2 tables one for users details and another for all other info
    or will that complicate it even more
    cheers
    Doug
    PHP Code:
    <?php 
    // Connects to your Database 
    $dbh=mysql_connect("localhost""car_doug""57") or die(mysql_error()); 
    mysql_select_db("car_users") or die(mysql_error()); 

    //Checks if there is a login cookie
    if(isset($_COOKIE['ID_my_site']))

    //if there is, it logs you in and directes you to the members page

    $username $_COOKIE['ID_my_site']; 
    $pass $_COOKIE['Key_my_site'];
    $check mysql_query("SELECT * FROM members WHERE username = '$username'")or die(mysql_error());
    while(
    $info mysql_fetch_array$check )) 
    {
    if (
    $pass != $info['password']) 
    {
    }
    else
    {
    header("Location: edit.php");

    }
    }
    }

    //if the login form is submitted
    if (isset($_POST['submit'])) { // if form has been submitted

    // makes sure they filled it in
    if(!$_POST['username'] | !$_POST['pass']) {
    die(
    'You did not fill in a required field.');
    }
    // checks it against the database

    if (!get_magic_quotes_gpc()) {
    $_POST['email'] = addslashes($_POST['email']);
    }
    $check mysql_query("SELECT * FROM members WHERE username = '".$_POST['username']."'")or die(mysql_error());

    //Gives error if user dosen't exist
    $check2 mysql_num_rows($check);
    if (
    $check2 == 0) {
    die(
    'That user does not exist in our database. <a href=add.php>Click Here to Register</a>');
    }
    while(
    $info mysql_fetch_array$check )) 
    {
    $_POST['pass'] = ($_POST['pass']);
    $info['password'] = ($info['password']);
    $_POST['pass'] = ($_POST['pass']);

    //gives error if the password is wrong
    if ($_POST['pass'] != $info['password']) {
    die(
    'Incorrect password, please try again.');
    }

    else 


    // if login is ok then we add a cookie 
    $_POST['username'] = stripslashes($_POST['username']); 
    $hour time() + 3600
    setcookie(ID_my_site$_POST['username'], $hour); 
    setcookie(Key_my_site$_POST['pass'], $hour); 

    //then redirect them to the members area 
    header("Location: edit.php"); 



    else 


    // if they are not logged in 
    ?> 
    <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post"> 
    <table border="0"> 
    <tr><td colspan=2><h1>Login</h1></td></tr> 
    <tr><td>Username:</td><td> 
    <input type="text" name="username" maxlength="40"> 
    </td></tr> 
    <tr><td>Password:</td><td> 
    <input type="password" name="pass" maxlength="50"> 
    </td></tr> 
    <tr><td colspan="2" align="right"> 
    <input type="submit" name="submit" value="Login"> 
    </td></tr> 
    </table> 
    </form> 
    <?php 


    ?>
    an old man of 60 trying to keep up with the youngsters he he
    http://lostpetsplymouth.net16.net

  9. #9
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Afternoon Doug, here's the bad news.....
    The tutorial you are following is going to cause you some MAJOR headaches
    I worked with another member (paramedic) as he was having the same problems.

    Give me a little time and I will write something up for you to follow.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  10. #10
    SitePoint Addict
    Join Date
    Jun 2007
    Location
    Plymouth uk
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks spike
    should i delete every thing and start again
    cheers
    Doug
    an old man of 60 trying to keep up with the youngsters he he
    http://lostpetsplymouth.net16.net

  11. #11
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    pretty much! you can keep the database table if you like but as far as the code goes - it's not good
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  12. #12
    SitePoint Addict
    Join Date
    Jun 2007
    Location
    Plymouth uk
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok cheers
    i will await your help before i do any thing
    cheers
    Doug
    ps dont mind making a small cash payment
    an old man of 60 trying to keep up with the youngsters he he
    http://lostpetsplymouth.net16.net

  13. #13
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    wow, timing doug!
    I have just finished writing it up

    btw, I have done it in such a way that the comments and text are all in the actual scripts so it can be referenced easily. I havent seen it done like that before so if you could give me some feedback on that and the scripts in general it would be appreciated

    OK - so to begin, are you comfortable?....

    First of all you need your SQL....

    members table
    Code:
    CREATE TABLE `members` (
      `id` int(6) NOT NULL AUTO_INCREMENT COMMENT 'members id',
      `username` varchar(12) NOT NULL COMMENT 'members username',
      `password` varchar(255) NOT NULL COMMENT 'members password',
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;
    
    
    /* dumping data */
    insert  into `members`(`id`,`username`,`password`) values (1,'spike','a60e7822190108e7bfa5015a3f57dea1'),(2,'doug','b07b89b1d596bc0d32cbabed34147efd');
    
    
    CREATE TABLE `membersinfo` (
      `id` int(12) NOT NULL AUTO_INCREMENT COMMENT 'record id NOT user',
      `usr_id` int(6) NOT NULL COMMENT 'member id',
      `realname` varchar(255) NOT NULL COMMENT 'members realname',
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;
    
    
    insert  into `membersinfo`(`id`,`usr_id`,`realname`) values (1,1,'Mike'),(2,2,'Doug');
    So there are 2 tables - members and membersinfo

    usernames/password:
    spike/spike
    doug/doug

    the php...

    1) save as functions.php

    functions.php
    PHP Code:
    <?php

    /* Basic login using php and mysql
        ** nothing clever or complicated :)
        ** Build mainly to demonstrate a login system
        ** that anyone can follow
        ** Requirements:
        ** PHP4+/PHP5+
        ** MySQL database
        **
        ** */

    /* functions.php
        ** This page is literally for the function that can
        ** be used in the script more than once or need to be
        ** called from different locations eg: login
        ** Also on this page are some basic congiuration items
        ** as this file is included in other pages
        ** 
        ** session_start();
        ** www.php.net/session_start
        ** Initialize session data
        **
        ** ini_set("display_errors", 2);
        ** ERROR_REPORTING(E_ALL);
        ** set up error reporting
        ** www.php.net/manual/en/function.error-reporting.php
        ** */
        



    /* session handler
        ** Start session
        ** append with @ depending on server config */
    @session_start();

    /* error handler
        ** set error reporting level to 0 to show no error, 2 to show */
    ini_set("display_errors"2);
    ERROR_REPORTING(E_ALL);


    /* define some useful constants
        ** */
    define('DB_USER''root');
    define('DB_PASS''peanuts2');
    define('DB_HOST''localhost');
    define('DB_BASE''spf');

    /* database connection
        ** connect to your MySQL database
        ** using the constants above.
        ** 
        ** */
    mysql_connect(DB_HOSTDB_USERDB_PASS);
    mysql_select_db(DB_BASE);
            



        
    /*------------------------------------->
        function: login form
        ** basic login form
        ** nothing fancy :)
    --------------------------------------*/
        
    function loginForm() {
            
            return 
    '
            <fieldset>
            <legend>Please Login</legend>
                <form name="loginForm" id="loginForm" method="post" action="">
                    <p><label for="usr">Username</label><br />
                        <input type="text" name="usr" value="" /></p>
                    <p><label for="psw">Password</label><br />
                        <input type="password" name="psw" value="" /></p>
                    <button type="submit" name="submit" value="SUBMIT">Login</button>
                    <input type="hidden" name="login" value="1"> 
                </form>
            </fieldset>
            '
    ;
        }
        
    /*------------------------------------->
        function: login process
        ** process the login form
    --------------------------------------*/

        
    function loginProcess($username$password) {
            
            
    /* never trust incoming data
                ** sanitise it and escape it 
                ** basic cleaning  
                ** mysql_real_escape_string (www.php.net/mysql_real_escape_string)
                ** trim (www.php.net/trim)
                ** */
                
            
    $username mysql_real_escape_string(trim($username));
            
            
    /* using md5 for password security
                ** if you are using plain password - stop it!
                ** if you insist on using plain passwords then 
                ** comment/hash the line below
                ** */
            
    $password md5($password);
            
            
    /* Run the query to find a match in the database
                ** selecting only the basic fields and 
                ** NOT using * 
                ** also using LIMIT 1 as there should only be one 
                ** result.....
                ** */
            
    $sql mysql_query("
                    select
                          id
                        , username
                        , password
                    from
                        members
                    where
                        username = '
    $username'
                    and 
                        password ='
    $password'
                    limit 1 
                "
    );
                
            
    /* are there any rows returned 
                ** from the login query?.....
                ** mysql_num_rows() returns the total number of rows
                ** found by the query 
                ** So if there is a row 
                ** */
            
    if(mysql_num_rows($sql) > 0) {
            
            
    /* assign a results handler to the
                ** returned fields.
                ** */
            
    $rows mysql_fetch_assoc($sql);
            
            
    /* register some session variables
                ** based on the database values */
            
    $_SESSION['usr_logged'] = 1
            
    $_SESSION['usr_id'] = $rows['id'];
            
    $_SESSION['usr_name'] = $rows['username'];
            
            
    /* now that the basic values are registered
                ** fire them off to the next page 
                ** using header("Location: nextPage.php");
                ** */
            
    header("location: members.php");
            
    /* exit() as we dont want the 
                ** script to carry on */
            
    exit();
                
            } else {
            
            
    /* but what happens if there are no results
                ** returned from the database?
                ** Make a polite error message
                ** */
            
    $errorMsg '<p>Sorry. Your details couldnt be found</p>';
            
            
    /* and return that value to the script
                ** for displaying */
            
    return $errorMsg;
            }    
            
        }

    /*------------------------------------->
        function: check auth
            is the usr_logged variable present?
            has the user logged in?    
    --------------------------------------*/
        
    function checkAuth() {
            
    /* is the SESSION usr_logged variable 
                ** anywhere? */
                
            /* if not - redirect them to somewhere they can login
                **    */    
            
    if(!isset($_SESSION['usr_logged'])) {
                
    header("Location: index.php");
                exit();
                return 
    false;
            } else {
            
    /* return true - not really needed but keeps things tidy! */
                
    return true;
            }
        }
        

    /*------------------------------------->
        function: get member details
            based on the usr_id session variable    
    --------------------------------------*/

        
    function getMemberDetails($id) {
            
            
    /* query the database using the session usr_id
                ** variable. Also left join the information table
                ** to get the extra information
                ** */ 
            
    $sql mysql_query("
                    select
                          members.id
                        , members.username
                        , members.password
                        , membersinfo.realname
                    from
                        members
                    left join
                        membersinfo
                    on
                        members.id=membersinfo.usr_id
                    where
                        members.id = 
    $id                
                "
    );
            
            
    /* for this tutorial there are no real details
                ** but if you had another table with more
                ** information such as address, postcode etc
                ** you can use the same theory
                ** */
            
            /* assign a results handler as we did earlier
                ** to handle the returning information */
            
    $rows mysql_fetch_assoc($sql);
            
            
    /* note that $rows is an ARRAY and as such holds the
                 ** information like:
                 ** $rows['usrname']
                 ** $rows['password']
                 ** etc... */
            
    return $rows;
            
        }

    ?>
    2) save as index.php

    index.php
    PHP Code:
    <?php
    /* include the functions file
        ** so that we can use those functions
        ** */
    include('functions.php');

    /* set up an empty variable that we can 'fill'
        ** later in the script.
        ** defining it here avoids the error message.....
        ** Undefined index $whatever on line X....
        ** */
    $msg '';

    /* Has the login form been sent?
        ** Check the $_POST global array for the hidden field
        ** Using a hidden field as they will always be sent with a form
        ** whereas the submit button wont always be there if the user hits
        ** enter.
        ** NB: Not sure if that still holds true with modern browsers but its
        ** a habit now :)
        ** */
    if(isset($_POST['login'])) {
        
    /* fill the $msg variable that we defined earlier with the
            ** results of the login function */
        
    $msg loginProcess($_POST['usr'], $_POST['psw']);
    }


    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>

    <head>
        <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
        <title>Index.php</title>
    </head>

    <body>

    <h1>Index</h1>
    <?php 
    /* down to the nitty gritty now!
        ** If the $msg variable is not equal to nothing
        ** then echo it
        ** It should only be full if the login failed.....
        ** */
    if($msg != '') {
        echo 
    $msg;
    }
    /* basic setup.....
        ** check if the session variable usr_logged is present
            ** if it isnt then the user cant have logged in so 
            ** give them the login form
            ** */
    if(!isset($_SESSION['usr_logged'])) {
        echo 
    loginForm();
    }


    ?>
    </body>
    </html>
    3) save as members.php

    members.php
    PHP Code:
    <?php
    /* include the functions file
        ** so that we can use those functions
        ** */
    include('functions.php');

    /* USR/MEMBER AUTH CHECK
        ** so this is our members page so we dont want any Tom, Dick or Harry
        ** looking at it so.....
        ** */
    checkAuth();
    /* if they have got to here, they should be logged in.....
        **/

    /* get the member details based on the usr_id held
        ** in the SESSION.
        ** */
    $memberDetails getMemberDetails($_SESSION['usr_id']);


    /* if the login form is on this page
        ** process it if it has been sent */
    if(isset($_POST['login'])) {
        
    $msg loginProcess($_POST['usr'], $_POST['psw']);
    }

    /* logging out */
    if(isset($_GET['logout'])) {
        unset(
    $_SESSION['usr_logged']);
        unset(
    $_SESSION['usr_name']);
        
        
    header("Location: index.php");
        exit();
    }
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>

    <head>
        <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
        <title>members.php</title>
    </head>

    <body>

    <h1>Members</h1>
    <a href="?logout">Logout</a>
    <?php 

    echo 'Welcome back '$_SESSION['usr_name'];

    /* $memberDetails holds the information returned from the function
        ** that gets all the information from the database
        ** */
    echo '<p>Members Realname is.... '$memberDetails['realname'] .'</p>';

    ?>
    <p>That is really all there is to it as a basic, bare bones login system.<br /><br />
    It has minimal security so that is something to look at next as is Adding a user to the database.</p>
    </body>
    </html>
    So that should get you going with the theory

    Let me know what you think
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  14. #14
    SitePoint Addict
    Join Date
    Jun 2007
    Location
    Plymouth uk
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    havnt looked at it yet
    but how do i copy and paste so it comes out as should do
    as i have copy and paste before i have to go through it and use return
    if you see what i mean
    cheers
    Doug
    an old man of 60 trying to keep up with the youngsters he he
    http://lostpetsplymouth.net16.net

  15. #15
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Here is a zip file with all the relevant files.
    Attached Files Attached Files
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  16. #16
    SitePoint Addict
    Join Date
    Jun 2007
    Location
    Plymouth uk
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok got it running but one problem dont know what password is
    and on the bottom of form there is this number
    b07b89b1d596bc0d32cbabed34147efd
    if you want to try
    www.djbcaravanhire.co.uk/test/index.php
    cheers
    Doug
    an old man of 60 trying to keep up with the youngsters he he
    http://lostpetsplymouth.net16.net

  17. #17
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Glad its working so far

    usernames/password:
    spike/spike
    doug/doug

    be back in a bit
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  18. #18
    SitePoint Addict
    Join Date
    Jun 2007
    Location
    Plymouth uk
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok to add a member i have a form and add form but which table should they be sent to as i have to add the field that are needed
    PHP Code:
    <form name="form" onsubmit="return ValidateRequiredFields();" action="add.php" method="post">
    <
    div id="info" style="width:360px;">

        <
    div align="left">
          <
    input type="hidden" name="pname" value="pic0.jpg">
          <
    strong>Select Choice: *</strong>
       &
    nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
           <
    select name="region">
            <
    option value="HIRE">4 Hire</option>
            <
    option value="EXCHANGE">4 Exchange</option>
            <
    option value="EXCHANGE/HIRE">Exchange and Hire</option>
            </
    select> <br>
          <
    br />
          <
    input name="name" type="text"
          <
    strong>Name: *</strong>    <br>
          <
    br />
          <
    input type="text" name="username"
          <
    strong>Username:</strong>    <br>
          <
    br />
          <
    input type="text" name="password"
          <
    strong>Password:</strong>    <br
          <
    br />
          <
    input type="text" name "email"
          <
    strong>Email: *</strong><br>
          <
    br />
          <
    input type="text" name "contact">
          <
    strong>Tel Number:</strong>   <br>
          <
    br />
          <
    input type="text" name="parkname"
          <
    strong>Park Name: *</strong>    <br>
          <
    br />
          <
    strong>Select County: *</strong
          <
    select name="county">
      <
    Option VALUE="South West">South West</option>
      <
    Option VALUE="South East">South East</option>
      <
    Option VALUE="Wales">Wales</option>
      <
    option value="Scotland">Scotland</option>
      <
    option value="London">London</option>
      <
    option value="East England">East of England</option>
      <
    option value="West Midlands">West Midlands</option>
      <
    option value="East Midlands">East Midlands</option>
      <
    option value="Yorkshire">Yorkshire Humberside</option>
      <
    option value="Northwest">North West</option>
      <
    option value="Northeast">North East</option>
      <
    option value="Other">Other</option>
            </
    select> <br>
          <
    br />
          <
    input type="text" name="parklocation">
          <
    strong>Park Location: *</strong>   <br>
          <
    br/>
          <
    input type="text" name="make">
          <
    strong>Make and Model: *</strong>   <br>
          <
    br/>
          <
    strong>Caravan Details:</strong><br>      
          <
    textarea name="caravandetails" cols="40" rows="5"></textarea><br>
          <
    br/>
          <
    strong>Smoking Allowed</strong><br />
          <
    input type="radio" name="smoke" value="yes" />
          <
    label for="smoke">Yes</label>
          <
    br>     
          <
    input type="radio" name="smoke" value="No" />
          <
    label for="smoke">No</label>
          <
    br />
          <
    strong>Pets Allowed</strong><br />
          <
    input type="radio" name="pets" value="yes" />
          <
    label for="pets">Yes</label>
          <
    br>     
          <
    input type="radio" name="pets" value="No" />
          <
    label for="pets">No</label>
          <
    br />
          <
    strong>Children Allowed</strong><br />
          <
    input type="radio" name="kids" value="yes" />
          <
    label for="kids">Yes</label>
          <
    br>     
          <
    input type="radio" name="kids" value="No" />
          <
    label for="kids">No</label>
          <
    br />
          <
    strong>Same Sex Groups Allowed</strong><br />
          <
    input type="radio" name="sex" value="yes" />
          <
    label for="sex">Yes</label>
          <
    br>     
          <
    input type="radio" name="sex" value="No" />
          <
    label for="sex">No</label>
          <
    br>
          <
    br/>
          <
    input type="submit" value="submit"/> 
        </
    div>
    </
    form
    and the add form
    PHP Code:
    //This gets all the other information from the form
    $region=$_POST['region']; 
    $name=$_POST['name'];
    $username=$_POST['username'];
    $password=$_POST['password'];
    $email=$_POST['email'];
    $contact=$_POST['contact'];
    $parkname=$_POST['parkname'];
    $county=$_POST['county'];
    $parklocation=$_POST['parklocation'];
    $make=$_POST['make'];
    $caravandetails=$_POST['caravandetails'];
    $smoke=$_POST['smoke'];
    $pets=$_POST['pets'];
    $kids=$_POST['kids'];
    $sex=$_POST['sex'];
    $pname=$_POST['pname'];

    // Connects to your Database 
     $dbh=mysql_connect("localhost", "car", "57") or die('I cannot connect to database because: ' .mysql_error()) ; 
    mysql_select_db("car"); 

    //Writes the information to the database 
    mysql_query("INSERT INTO `members` VALUES ('$ID', '$region', '$name', '$username', '$password', '$email', '$contact' , '$parkname', '$county', '$parklocation', '$make', '$caravandetails', '$smoke', '$pets', '$kids', '$sex', '$pname', '$enq')");
     
    //compose the mail message        
     $msg= "New Record\n Region: $region, Name: $name, Email: $email ";       
    //send the mail       
    mail('caravanhire3@googlemail.com','New Record',$msg)

    ?> 
    <?php $msg"Could you Please Email a Photo to caravanhire3@googlemail.com as soon as Possable,Thank You Doug"mail($email'Welcome to my site'$msg); ?>
    <?php
    echo "your information has been added to the directory You will be redirected in three seconds!><br /><br /> 

            <div class='info'>If you don't wish to wait, <a href='index.php'>click here</a>"
    ;            
            echo
    '<meta http-equiv="REFRESH" content="2;url=index.php">';
    ?>
    an old man of 60 trying to keep up with the youngsters he he
    http://lostpetsplymouth.net16.net

  19. #19
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    add them to the memberinfo table. When I get on later I will help you more.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  20. #20
    SitePoint Addict
    Join Date
    Jun 2007
    Location
    Plymouth uk
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok added some details and getting this error

    Notice: Undefined index: parkname in /home/caravanh/public_html/test/members.php on line 57
    Park Name:


    Notice: Undefined variable: info in /home/caravanh/public_html/test/members.php on line 58
    County:

    PHP Code:
    echo '<p>Members Realname is.... '$memberDetails['realname'] .'</p>';
    echo 
    '<p>Contact:..'.$memberDetails['contact'] . ' </p>';
    echo 
    '<b>Park Name:</b> '.$memberDetails['parkname'] . '</p>'
    bet it some thing i am doing
    cheers
    Doug
    an old man of 60 trying to keep up with the youngsters he he
    http://lostpetsplymouth.net16.net

  21. #21
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Remeber that the results can only use the rows asked for in the database query.
    By that I mean if your query was
    Code:
    select
    	  id
    	, username
    from
    	members
    where
    	id = 1
    you can then only use the id and username values, you couldn't use realname as you ahvent asked for it in the query.

    (I think that makes sense!)
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  22. #22
    SitePoint Addict
    Join Date
    Jun 2007
    Location
    Plymouth uk
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for all your help Spike
    have gone a diff route and seems to be working sort of
    cheers
    Doug
    an old man of 60 trying to keep up with the youngsters he he
    http://lostpetsplymouth.net16.net

  23. #23
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    It's a pleasure Doug and what do you mean sort of?!!!!
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  24. #24
    SitePoint Addict
    Join Date
    Jun 2007
    Location
    Plymouth uk
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well its working i think just needs tidy up as looks a bit messy
    cheers
    Doug
    an old man of 60 trying to keep up with the youngsters he he
    http://lostpetsplymouth.net16.net


Bookmarks

Posting Permissions

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