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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jan 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP Login Form help

    ok, im new to php and im do a fun website to help learn php. Im trying to make my first php site with an account type system, and i have the form working and it will go to the profile page when i enter a username and password, the trouble is i can enter anything... and it will still go to the profile.

    What i want it to do is to login with the correct username and password and if the username and password is wrong i want it to redirect to my error.php page with and echo of Login Failed

    Can anyone Help?

    heres the code i have i have written along with a youtube tutorial

    Code:
      <?php
    		if(isset($_POST['user']))
    		{	
      $user = $_POST['user'];
      $pass = $_POST['pass'];
      
      if ($user&&$pass)
      { 
      $connect = mysql_connect("66.7.207.100", "leftblank","leftblank") or die ("Couldn't Connect!");
      mysql_select_db("nxc") or die ("Couldnt find db");
      
      $query = mysql_query("SELECT * FROM nxc WHERE username='$user'");
      
      $numrows = mysql_num_rows($query);
      
      if($numrows!=0)
      {
     
      while (mysql_fetch_assoc($query));
      {
      
      $dbusername = $row['user'];
      $dbpassword = $row['pass'];
      
      }
      
      if($user==$dbusername&&$pass==$dbpassword) 
      {
      echo ("Login Successful");
     
      }
      else echo ("Login Failed");
      }
      else die("That user doesnt exist!");
      }
      else die("Please enter a Username and a Password!");
      }
      ?>

  • #2
    NoJ
    NoJ is offline
    New to the CF scene
    Join Date
    Mar 2009
    Location
    Germany
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    MasterGraphics,

    if your
    Code:
    if($user==$dbusername&&$pass==$dbpassword)
    you currently dont actually do anything except for echoing a message.
    If you add
    Code:
    header( 'Location: error.php' )
    to an error-branch, then this page will be displayed.

  • #3
    New to the CF scene
    Join Date
    Jan 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok so where would i place that header code? and it will go to the error page if the password is wrong? and to the profile if its correct?

    sorry still pretty new at php, started two days ago.


  •  

    Posting Permissions

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