-1

dont know why this form is not working.... while i submit this after putting username and password.. it donot show any thing after submission

<?php 
 include "connect_to_mysql.php";
 if(isset($_POST['log']))
 {
 $user= $_POST['user'];
 $pass=md5($_POST['pass']);

   $sql=mysql_query("select* from login where user= '$user' AND pass='$pass'    LIMIT 3 ");
  $data=mysql_fetch_array($sql);

  $UserName= $data['user'];   
  $Password= $data['pass'];
  $type= $data['type'];
  $name= $data['name'];

  if($user==$username && $pass==$password){
  session_start();
  $_SESSION['name']=$name;
  if($type=='admin')
  {
         header("location: index.php");
  }
  else if($type=='vender1')
 {
         header("location: vender1.php");
  }

 }




  else {
        echo 'That information is incorrect, try again <a href="index.php">Click Here</a>';
    exit();
  }
  }
  ?>

database is created manually and login table has 5 columns named as id, name. user, pass, type.

     <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
   <head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
   <title> Log In </title>
   <link rel="stylesheet" href="style.css" type="text/css" media="screen" />
   </head>

   <body>
   <br /><br /><br /><br /><br /><br /><br /><br />
   <br /><br /><br /><br />
   <div id="mainWrapper">
   <?php include_once("header.php") ?></div>
   <div id="pageContent"><br /><br /><br />
   <div align="right" style="margin-right:24px; color:#FF0000">
   <h2>Please Log In To Manage the Inventary</h2>
   <br /><br />
   <form id="form" name="form" method="post" action="login.php">
     <h2 style="padding-right:200px;">User Name:</h2>
       <input name="user" type="text" id="user" size="40"   style="height:20px;" />
     <br /><br />
     <h2 style="padding-right:210px;">Password:</h2>
     <input name="pass" type="password" id="pass" size="40" style="height:20px;" />
    <br />
    <br />
    <br />

      <input type="submit" name="button" id="button" value="Log In" />

    </form>
   <p>&nbsp; </p>
   </div>
   <br />
   <br />
   <br />
   </div>

    </div>
     </body>
     </html>

i m stucked here.. please make me out of this

violator667
  • 469
  • 4
  • 19
deep singh
  • 339
  • 3
  • 5
  • 14

2 Answers2

1

You have error in your query, you are writing select* but there should be a space like so select *

$sql = mysql_query("select * from login where user= '$user' AND pass='$pass' LIMIT 3 ") or die(mysql_error());

EDIT

Also YOU MUST HAVE TO PUT session_start(); as the first line of your code... else it would not work.

So make this as your first lines of code

session_start();
error_reporting(E_ALL); // to see if there is error in code

And also PHP varialble names are case-sensitive,

Variables in PHP are represented by a dollar sign followed by the name of the variable. The variable name is case-sensitive.

So please change

if($user==$username && $pass==$password)

to

if($user==$UserName && $pass==$Password)
Umair Ayub
  • 19,358
  • 14
  • 72
  • 146
1

Run the following code ,

   $sql=mysql_query("select* from login where user= '$user' AND pass='$pass'    LIMIT 3 ");
  $data=mysql_fetch_array($sql);

  $UserName= $data['user'];   
  $Password= $data['pass'];
  $type= $data['type'];
  $name= $data['name'];

  if($user==$username && $pass==$password){
  session_start();
  $_SESSION['name']=$name;
  if($type=='admin')
  {
         header("location: index.php");
  }
  else if($type=='vender1')
 {
         header("location: vender1.php");
  }

 }




  else {
        echo 'That information is incorrect, try again <a href="index.php">Click Here</a>';
    exit();
  }
  ?>

You have not used $_POST['log'] in the form ....

In your code you have used if(isset($_POST['log'])) , i have removed that because you have not using 'log' in your form.

user1665624
  • 91
  • 1
  • 1
  • 7