SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 42 of 42
  1. #26
    SitePoint Zealot
    Join Date
    Dec 2004
    Location
    Telford, UK.
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Message for SWDEV really, but if anyone can help then great.

    I've modified your above code to tailor around my website but there are 2 things that I'm unsure how to do.

    1 - If the username/password is incorrect how can I get the error messages to appear just above the input boxes instead of top of the page.
    2 - Where is the best place to insert the following html line.

    HTML Code:
    <meta http-equiv="Page-Enter" content="blendTrans(Duration=1.0)">
    The modifed version of your php code is
    PHP Code:
    <?php
      session_start
    ();
      
      
    $error_msg '';
      
    $username '';
      
    $password '';
      
      
    // clear session variables
      
    $_SESSION['login'] = '';
      
    $_SESSION['username'] = '';
      
    $_SESSION['password'] = '';
      
    // OPEN THE DATABASE CONNECTION
    $conn=mysql_connect ("localhost""*********""*********") or die ('I cannot connect to the database because: ' mysql_error());

    // PICK THE DATABASE TO USE
    mysql_select_db ("************",$conn); 
      
      
    // check if the form is submitted
      
    if(isset($_POST['submit_form']))
      {
          
    // validate POST variables.
          // Should do better checks e.g. make sure only alphanumeric characters in username / password
          
    if(!$_POST['username'])
          {
              
    $error_msg .= 'Please complete the Username<br>';
          }
        
    $username $_POST['username'];
      
          if(!
    $_POST['password'])
          {
              
    $error_msg .= 'Please complete the Password<br>';
          }
        
    $password $_POST['password'];
      
          
    // if no errors carry on.
          
    if('' == $error_msg
          {
             
    $sql 'SELECT username, password FROM Members WHERE';
             
    $sql .= ' username = \'' $username '\'';
             
    $sql .= ' AND ';
             
    $sql .= ' password = \'' $password '\'';
          
    $login_check mysql_query($sql);
          
          if (
    false === $login_check)
          {
              
    $error_msg .= $sql ' failed due to ' mysql_error() . '<br />'
          }
          else
          {
            
    // get the rows from the database
            
    $login_rows mysql_num_rows($login_check);
        
             
    // there should be only 1 row in the database for this username / password combination
            
    if(== $login_rows)
            {
              
    // define session variables
              
    $_SESSION['login'] = 'Logged';
              
    $_SESSION['username'] = $username;
              
    $_SESSION['password'] = $password;
              
    // redirect
              
    header('Location: members_page.php');
              exit;
            }
            else
            {
                
    $error_msg .= ' Invalid username / password combination<br />';
            }
          }
          }
          echo 
    $error_msg;
      }
      
      
    ?>


    <body bgcolor="#F6F7EB">
    <p align="center"><font face="Tahoma" size="7">Paramedic Log</font></p>  
    <p align="left"><font face="Tahoma"><a href="my link">Home
    Page</a></font></p>
    <h1 align="center"><font face="Tahoma">Please enter your username and password</font></h1><p align="center"><font face="Tahoma"><a href="http://my link">Click
    here to Register with Paramedic Log</a></font></p>&nbsp;

      <form name="submit_data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
      <input type="text" name="username" value="<?php echo $username ?>"><br>
      <input type="password" name="password" value="<?php echo $password?>">
      <input type="hidden" name="submit_form">
      <input type="submit" name="submit" value="submit" label="submit">
      
      </form>
    Hope you can help. Cheers.

  2. #27
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    just change one line
    PHP Code:
      session_start();
      
      $error_msg = '';
      $username = '';
      $password = '';
      
      // clear session variables
      $_SESSION['login'] = '';
      $_SESSION['username'] = '';
      $_SESSION['password'] = '';
      
    // OPEN THE DATABASE CONNECTION
    $conn=mysql_connect ("localhost", "*********", "*********") or die ('I cannot connect to the database because: ' . mysql_error());

    // PICK THE DATABASE TO USE
    mysql_select_db ("************",$conn);
      
      // check if the form is submitted
      if(isset($_POST['submit_form']))
      {
          // validate POST variables.
          // Should do better checks e.g. make sure only alphanumeric characters in username / password
          if(!$_POST['username'])
          {
              $error_msg .= 'Please complete the Username<br>';
          }
        $username = $_POST['username'];
      
          if(!$_POST['password'])
          {
              $error_msg .= 'Please complete the Password<br>';
          }
        $password = $_POST['password'];
      
          // if no errors carry on.
          if('' == $error_msg)
          {
             $sql = 'SELECT username, password FROM Members WHERE';
             $sql .= ' username = \'' . $username . '\'';
             $sql .= ' AND ';
             $sql .= ' password = \'' . $password . '\'';
          $login_check = mysql_query($sql);
          
          if (false === $login_check)
          {
              $error_msg .= $sql . ' failed due to ' . mysql_error() . '<br />';
          }
          else
          {
            // get the rows from the database
            $login_rows = mysql_num_rows($login_check);
        
             // there should be only 1 row in the database for this username / password combination
            if(1 == $login_rows)
            {
              // define session variables
              $_SESSION['login'] = 'Logged';
              $_SESSION['username'] = $username;
              $_SESSION['password'] = $password;
              // redirect
              header('Location: members_page.php');
              exit;
            }
            else
            {
                $error_msg .= ' Invalid username / password combination<br />';
            }
          }
          }
         // echo $error_msg;//NOT HERE
      }
      
      ?>


    <body bgcolor="#F6F7EB">
    <p align="center"><font face="Tahoma" size="7">Paramedic Log</font></p>  
    <p align="left"><font face="Tahoma"><a href="my link">Home
    Page</a></font></p>
    <h1 align="center"><font face="Tahoma">Please enter your username and password</font></h1><p align="center"><font face="Tahoma"><a href="http://my link">Click
    here to Register with Paramedic Log</a></font></p>&nbsp;

    <!-- SEE HERE*************************-->
    <?php echo $error_msg;  //THIS WOULD DO WHAT YOU WANT?(i think so)>
    <!-- SEE HERE*************************-->

      <
    form name="submit_data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
      <
    input type="text" name="username" value="<?php echo $username ?>"><br>
      <
    input type="password" name="password" value="<?php echo $password; ?>">
      <
    input type="hidden" name="submit_form">
      <
    input type="submit" name="submit" value="submit" label="submit">
      
      </
    form>
    i don't know what that meta tag does but i know all the meta tags go in <head></head> section of body

  3. #28
    SitePoint Zealot
    Join Date
    Dec 2004
    Location
    Telford, UK.
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Excellent thank you.

    The Meta Tag merely faded the web page in. I've decided not to use it now anyway.

  4. #29
    SitePoint Zealot
    Join Date
    Dec 2004
    Location
    Telford, UK.
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Regarding the above code for a login.

    My brain is dead now and can't figure out what the name of the web page it refers to. Is it 'members_page.php' and if it is why does it not work in my web page? Do I need stuff in this 'members_page.php' that refers to the sessions that we just logged in with? If so, then how do I do that? Sorry for the complete novice question.

  5. #30
    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)
    x-factor.
    1./ I missed out two closing braces at the bottom of the code (both before the closing ?>) - sorry!

    2./ The code that I posted as the error line was a cross thread and wasn't to be included in your code - again, sorry if I confused you.

    3./ swdev's code (the extention of mine (just alot neater ) should be the one you consider using.

    webnoob.
    1./ SQL can be in any case as long as it is logical and not something like ("SeLeCT * FrOM myTAblE") not that this wouldn't work but it just looks terrible!!!!

    2./ Don't get disheartened, if you have been given duff advice in the past and now you are passing it on, it is better to be corrected politely than flamed and spit roasted!
    Now you know!!!!

    3./ Your code wasn't that bad!!!!

    swdev.
    1./ Thanks for continuing with my code, you have a nice way of putting things!

    2./ Maybe that thread is a good idea! Think about it....!

    X-Factor, does this all work now?

    Regards and happy new year

    SpikeZ
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  6. #31
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you've got a lot to say SpikeZ

    Thanks for the post and dont worry i didnt get disheartened, we all need to learn somehow and had i not passed my wrong info on to x-factor i wouldnt have know it was wrong

    Sooo..
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  7. #32
    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)
    Quote Originally Posted by Caduceus
    Regarding the above code for a login.

    My brain is dead now and can't figure out what the name of the web page it refers to. Is it 'members_page.php' and if it is why does it not work in my web page? Do I need stuff in this 'members_page.php' that refers to the sessions that we just logged in with? If so, then how do I do that? Sorry for the complete novice question.

    The members_page.php was used just as a page to direct to. It is the page that has the members only content on it and so you would need some code at the top.
    PHP Code:
    <? 
    session_start
    ();
    is($_SESSION['login'] != 'Logged') {
    header("Location: error.php");


    # continue
    SpikeZ
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  8. #33
    SitePoint Zealot
    Join Date
    Dec 2004
    Location
    Telford, UK.
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've just that code on the redirct page and it comes up with this error message...

    Parse error: parse error, unexpected T_STRING in /home/kilvert/public_html/paramedic/memberhome.php on line 2

  9. #34
    SitePoint Wizard swdev's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Post your memberhome.php file, then we can take a look.

  10. #35
    SitePoint Zealot
    Join Date
    Dec 2004
    Location
    Telford, UK.
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, pretty much as above but here it is anyway.

    PHP Code:
    <? php
    session_start
    (); 
    is($_SESSION['login'] != 'Logged') { 
    header("Location: error.php"); 

    ?>

    <html>
    <body bgcolor="#F6F7EB">
    <p align="center"><font face="Tahoma" size="7">Test</font></p>
    </html>

  11. #36
    SitePoint Wizard swdev's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Change is to if on line 2

  12. #37
    SitePoint Zealot
    Join Date
    Dec 2004
    Location
    Telford, UK.
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Done, but no difference. Same error message. Sorry.

  13. #38
    SitePoint Wizard swdev's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My fault. I should really test out my answers before posting them

    Here's the - hopefully - fixed code

    PHP Code:
        <?php
        session_start
    ();
        if(
    $_SESSION['login'] != 'Logged') {
        
    header("Location: error.php");
        }
        
    ?>
        
        <html>
        <body bgcolor="#F6F7EB">
        <p align="center"><font face="Tahoma" size="7">Test</font></p>
        </body>
        </html>
    changes are

    *) to the open php tag - no space between the ? and the php
    *) added a </body> tag to the HTML part of your code
    *) is changed to if on line 2

  14. #39
    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 is new year!
    My fault with the is($_SESSION was torn between session_is_registered and if($_SESSION

    Hold my hands up!

    SpikeZ
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  15. #40
    SitePoint Wizard swdev's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    New Years resolution - drink less at next years party

  16. #41
    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)
    That's the problem..... I don't drink!!!
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  17. #42
    SitePoint Zealot
    Join Date
    Dec 2004
    Location
    Telford, UK.
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Excellent - thanks everyone!!


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
  •