Jump to content

Recommended Posts

Wow thanks m8! Working flawlessly with new editor :)

 

I have a problem when logging in..

Basicly, i want to select & store/save the member if from the members table where name = username from form.

To do this i have:

// Create query
  $id = "SELECT member_id FROM `members` "
  ."WHERE `name`='".$_POST["username"]."' ";

Now i want to check if username + password is correct, and their account is not locked.

I start to check if the username is valid (once again), then check if they are locked, and then check the password where the member id = the one we found earlier.

To do this:

// Create query
  $id = "SELECT member_id FROM `members` "
  ."WHERE `name`='".$_POST["username"]."' ";

$q = "SELECT * FROM `members` "
  ."WHERE `name`='".$_POST["username"]."' "
  ."AND `p_locked`=0 "
  ."AND SELECT field_13 FROM `pfields_content` "
  ."WHERE `id`='".$id."' "
  ."AND WHERE `field_13`=('".$_POST["password"]."') "
  
  ."LIMIT 1";
// Run query
$r = mysql_query($q);

if ( $obj = @mysql_fetch_object($r) )
  {
  // Login good, create session variables
  $_SESSION["valid_id"] = $obj->id;
  $_SESSION["valid_user"] = $_POST["username"];
  $_SESSION["valid_time"] = time();

  // Redirect to member page
  Header("Location: shop.php");
  }
else
  {
  // Login not successful
  die("Sorry, could not log you in. Wrong login information.
  <br> Or your fg has been locked. Please contact Smilie.");
  }
}

 

Full code::

 

<?php
session_start();
// dBase file
include 'inc/config.php';

if ($_GET["op"] == "login")
{
if (!$_POST["username"] || !$_POST["password"])
  {
  die("You need to provide a username and FG-Pass.");
  }

// Create query
  $id = "SELECT member_id FROM `members` "
  ."WHERE `name`='".$_POST["username"]."' ";

$q = "SELECT * FROM `members` "
  ."WHERE `name`='".$_POST["username"]."' "
  ."AND `p_locked`=0 "
  ."AND SELECT field_13 FROM `pfields_content` "
  ."WHERE `id`='".$id."' "
  ."AND WHERE `field_13`=('".$_POST["password"]."') "
  
  ."LIMIT 1";
// Run query
$r = mysql_query($q);

if ( $obj = @mysql_fetch_object($r) )
  {
  // Login good, create session variables
  $_SESSION["valid_id"] = $obj->id;
  $_SESSION["valid_user"] = $_POST["username"];
  $_SESSION["valid_time"] = time();

  // Redirect to member page
  Header("Location: shop.php");
  }
else
  {
  // Login not successful
  die("Sorry, could not log you in. Wrong login information.
  <br> Or your fg has been locked. Please contact Smilie.");
  }
}
else
{
//If all went right the Web form appears and users can log in
echo "<form action=\"?op=login\" method=\"POST\">";
echo "Username: <input name=\"username\" size=\"15\"><br />";
echo "FG-Password: <input type=\"password\" name=\"password\" size=\"8\"><br />";
echo "<input type=\"submit\" value=\"Login\">";
echo "</form>";
}






?>

 

Error when trying to login:

Username/password wrong.. No php error.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.