0

Pls help me with this code..

<?php

        include "dbConfig.php";

        if ($_GET["op"]=="login")
  {
  if (!$_POST["FullName"] || !$_POST["StudentID"])
        {
        die("You need to provide a username and password.");
        } 
  $q = "SELECT * FROM `register` 
        WHERE `FullName`='".$_POST["FullName"]."' 
        AND `StudentID`='".$_POST["StudentID"]."' 
        LIMIT 1";
  $r = mysql_query($q);

  if ($obj = @mysql_fetch_object($r))
        {
        $_SESSION["FullName"] = $_POST["FullName"];
        $_SESSION["StudentID"] = $_POST["StudentID"];
        header("location:members.php");
        }
  else
        {

        die("Sorry, could not log you in. Wrong login information.");
        }
  }
  else
  {
  echo "<form action=\"?op=login\" method=\"POST\">";
  echo "Username: <input name=\"StudentID\" size=\"15\"><br />";
  echo "Password: <input type=\"password\" name=\"password\" size=\"8\"><br />";
  echo "<input type=\"submit\" value=\"Login\">";
  echo "</form>";
  }
?>

The problem is it is still saying "You need to provide a username and password." please anyone help me..
My username is the FullName and my password is the StudentID..

Edited by janskey15

2
Contributors
3
Replies
7
Views
4 Years
Discussion Span
Last Post by LastMitch
0

@janskey15

The problem is it is still saying "You need to provide a username and password." please anyone help me.

It seems like there's something wrong with your query:

      $q = "SELECT * FROM `register` WHERE `FullName`='".$_POST["FullName"]."'
AND `StudentID`='".$_POST["StudentID"]."'LIMIT 1";

Try this:

$r = mysql_query($q);
if ($r === FALSE) {
   die(mysql_error());
}

To see whether the query work or not.

Where is your id to confirm that the user is register?

If your query doesn't work then try this (I made a little change):

From this:

$q = "SELECT * FROM `register` WHERE `FullName`='".$_POST["FullName"]."' AND `StudentID`='".$_POST["StudentID"]."'LIMIT 1";
$r = mysql_query($q);
if ($obj = @mysql_fetch_object($r))
{
$_SESSION["FullName"] = $_POST["FullName"];
$_SESSION["StudentID"] = $_POST["StudentID"];
header("location:members.php");
}

To this:

$q = "SELECT * FROM register WHERE FullName='$FullName' AND StudentID='$StudentID' LIMIT 1";
$r = mysql_query($q);
if ($obj = @mysql_fetch_object($r))
{
$_SESSION["FullName"] = $FullName;
$_SESSION["StudentID"] = $StudentID;
header("location:members.php");
}

I don't know if it's gonna work or not because I don't have a db. You need to test it and tell me whether it work or not.

Edited by LastMitch: grammer

0

@janskey15

thank you sir..it worked..

It's great to hear that it solve! Can you click Mark Question Solve on the bottom left corner so the thread is close and solve so noone can add stuff to it. Thanks.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.