0
session_start();
      include_once 'oesdb.php';

 //redirect to registration page
      if(isset($_REQUEST['register']))
      {
            header('Location: register.php');
      }
      else if($_REQUEST['stdsubmit'])
      {

 //Perform Authentication
          $result=executeQuery("select *,DECODE(stdpassword,'oespass') as std from student where stdname='".htmlspecialchars($_REQUEST['name'],ENT_QUOTES)."' and stdpassword=ENCODE('".htmlspecialchars($_REQUEST['password'],ENT_QUOTES)."','oespass')");
          if(mysql_num_rows($result)>0)
          {

              $r=mysql_fetch_array($result);
              if(strcmp(htmlspecialchars_decode($r['std'],ENT_QUOTES),(htmlspecialchars($_REQUEST['password'],ENT_QUOTES)))==0)
              {
                  $_SESSION['stdname']=htmlspecialchars_decode($r['stdname'],ENT_QUOTES);
                  $_SESSION['stdid']=$r['stdid'];
                  unset($_GLOBALS['message']);
                  header('Location: stdwelcome.php');
              }else
          {
              $_GLOBALS['message']="Check Your user name and Password.";
          }

          }
          else
          {
              $_GLOBALS['message']="Check Your user name and Password.";
          }
          closedb();

This is part of my index.php. It registers successfully and when I check the database on the server, see the new user but by the time I try to login, it accepts by not showing invalid password, but it refuses to login. I guess its not creating the session needed to login.

Andre Silva
  • 4,782
  • 9
  • 52
  • 65
donztobs
  • 1
  • 1
  • 1
    Welcome to SO :) [**Please, don't use `mysql_*` functions in new code**](http://bit.ly/phpmsql). They are no longer maintained [and are officially deprecated](http://j.mp/XqV7Lp). See the [**red box**](http://j.mp/Te9zIL)? Learn about [*prepared statements*](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://j.mp/QEx8IB) will help you decide which. If you choose PDO, [here is a good tutorial](http://j.mp/PoWehJ). – ulentini Apr 13 '13 at 13:59
  • thanks, will go through the link. Im kinda new to php. im a java programmer but just need to quickly get through a web page. – donztobs Apr 13 '13 at 14:22
  • Uby i went through but was having hard times converting to the PDO. please can you help me make the whole project work. I want to learn php as fast as possible and i was advised to get a complete project and start examining how it work. i could send you the zipped file. – donztobs Apr 13 '13 at 14:50
  • You need to debug your code. Read [How to get useful error messages in PHP?](http://stackoverflow.com/q/845021/1409082). – Jocelyn Apr 13 '13 at 18:19
  • perhaps `else if(isset($_REQUEST['stdsubmit']))` – Amir Apr 13 '13 at 20:36
  • the else if(isset($_REQUEST['stdsubmit'])) must be working well because when i open it on the browser, it recognises valid entries by not displaying invalid username or password. i think the problem is "creating the session". – donztobs Apr 14 '13 at 13:17

0 Answers0