Hi,
if user is not the registered user first he has to register and then login, my login page is working but i want to validate whether he is an registered user or not. i had written some code but its giving some problem , can any one help me plz...this is actually not a full code what i have given below.

<?php
include 'db.php';

$username = $_POST;
$password = $_POST ;


$q = "SELECT * FROM `userdetail` WHERE username='".$username."' AND password='".$password."'";
$result = mysql_query($q);


if(($
?>

Recommended Answers

All 5 Replies

It's better this way:

$q = "SELECT * FROM `userdetail` WHERE username='$username'";

$rs = mysql_query($q);
$rw = mysql_fetch_array($rs);

if($rw["password"]!=$password){
die('Acces denied'); // .. or something
}

thanks

Hello..

Use this code in your page with your database names...

you will get what you want..

<?
session_start();
include('functions.php');


if($_SERVER=="POST"){


$qer="select * from admin where username='".$_POST."' and password='".$_POST."'";
$res=mysql_query($qer);
$num=mysql_num_rows($res);
if($num==0)
{
$msg=1;
}
else if($num==1)
{
session_unregister("user_name");
session_register("user_name");
$_SESSION=$_POST;


session_unregister("adminid");
session_register("adminid");
$_SESSION=getdata("admin","id","username='".$_POST."' and password='".$_POST."'");


echo'<script language="javascript">window.location.href="welcome.php";</script>';
}
}
?>

And use this below code where ever you want to print like invalid user:
<? if(!empty($msg) && $msg==1){echo "Invalid user";}?>

Thanks,

ShantI

we need to know what the error is to help you. if you would post your full code that would help as well.

hi...

I am just continuing your code....

<?php
include 'db.php';

$username = $_POST;
$password = $_POST ;


$q = "SELECT * FROM userdetail WHERE username='$username' AND password='$password.'";
$result = mysql_query($q);
$numrows=mysql_num_rows($result);
if($numrows==0)
echo "invlid user";
else
echo "logged in successfully";
?>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.