Need some login form help

Asked By 0 points N/A Posted on -
qa-featured

Hi everyone ,

I want to add user registration feature to my existing website so after the registration user must be able to login,

How can I have a database to store user names and passwords for each users?

SHARE
Best Answer by Sonaiya John
Answered By 0 points N/A #94446

Need some login form help

qa-featured

First of all create the html page with name of login.php as below

<form action="login_process.php" method="POST">

   USERNAME:<input type="text" name="name"><br />

   Password:<input type="password" name="password" ><br />

   <input type="submit" name="submit" value="LOG IN">

</form>

Then create the login_process.php page as below

<?php

include 'db_connect.php';



$name=$_POST['name'];

$password=$_POST['password'];

$sql="SELECT * FROM user_info WHERE user_name='$name'and password='$password'";

$result=mysql_query($sql);

$count=mysql_num_rows($result);

if($count==1)

{

    header("location:newpost.php");



}

else{

    echo "Wrong Username or Password";

}



?>

where db_connect.php page is

<?php

        $a="localhost";

        $b="root";

        $c="";



        $con = mysql_connect($a,$b,$c);



        if(!$con)

        {

            die('Could not connect:' . mysql_error());

        }



        mysql_select_db("wblog", $con);

        

?>

where user_name and password are tables in the database wblog…

Hope you got the answer if you are smart enough or used php and mysql before..

P.S. if you get any trouble with this ..do inform me..

Thanks

Best Answer
Best Answer
Answered By 0 points N/A #94447

Need some login form help

qa-featured

<?php

if(isset($_POST['submit']))
{
include("include/connection.php");
$a=$_POST["name"];
$b=$_POST["email"];
$c=$_POST["password"];
$d=$_POST["country"];
$e=$_POST["state"];
$f=$_POST["city"];
$g=$_POST["gender"];
$h=$_POST["phone_no"];
$i=$_POST["mobile"];
$j=$_POST["contact_person"];
$k=$_POST["address"];
$l=$_POST["query"];
$query=mysql_query("insert into tbl_insert (name,email,password,country,state,city,gender,phone_no,mobile,contact_person,address,query) values ('$a','$b','$c','$d','$e','$f','$g','$h','$i','$j','$k','$l')")or die(mysql_error());
if($query)
{
echo "ok inserted";
}
else
{
echo "wrong";
}}
?>
 
This is the PHP coding for registration you have to create same column names in your table also like s_no, name, email, password and so on…..
 
This is the related html coding
 
<form action="" method="post" name="form">
<table width="200" border="0">
  <tr>
    <td>name:</td>
    <td><label>
      <input type="text" name="name">
    </label></td>
  </tr>
  <tr>
    <td>email:</td>
    <td><label>
      <input type="text" name="email">
    </label></td>
  </tr>
  <tr>
    <td>password:</td>
    <td><label>
      <input type="password" name="password">
    </label></td>
  </tr>
  <tr>
    <td>country:</td>
    <td><label>
      <select name="country">
 <option>india   </option>
<option>pakistan  </option>
 <option>china   </option>
 <option>
russia   </option>
 <option>england   </option>
 <option>bhutan   </option>
 <option>
 nepal   </option>
      </select>
    </label></td>
  </tr>
  <tr>
    <td>state:</td>
    <td><label>
      <select name="state">
 <option>
 haryana   </option>
 <option>
 bihar   </option>
        </select>
    </label></td>
  </tr>
  <tr>
    <td>city:</td>
    <td><label>
      <select name="city">
 <option>
 ambala   </option>
 <option>
 rohtak   </option>
      </select>
    </label></td>
  </tr>
  <tr>
    <td>gender:</td>
    <td><label>
      <input name="gender" type="radio" value="male">
    </label>
      <label>
      male
      <input name="gender" type="radio" value="female">
      female      </label></td>
  </tr>
  <tr>
    <td>phone no: </td>
    <td><label>
      <input type="text" name="phone_no">
    </label></td>
  </tr>
  <tr>
    <td>mobile:</td>
    <td><label>
      <input type="text" name="mobile">
    </label></td>
  </tr>
  <tr>
    <td>contact person: </td>
    <td><label>
      <input type="text" name="contact_person">
    </label></td>
  </tr>
  <tr>
    <td>address:</td>
    <td><label>
      <input type="text" name="address">
    </label></td>
  </tr>
  <tr>
    <td>query</td>
    <td><label>
      <textarea name="query"></textarea>
      <input type="submit" name="submit" value="Submit">
    </label></td>
  </tr>
  <tr>
  <td>  </td>
  </tr>
</table>
</form>
 
connection.php :-
 
<?php
$a=mysql_connect("localhost","root","");
mysql_select_db("registration",$a);
?>
 
If you still don't get it then please let me know if i can help you further.

 

Answered By 0 points N/A #195171

Need some login form help

qa-featured

Connection.php



<?php

Mysql_connect(“localhost”,”root”,””);

Mysql_select_db(“user”);

Here you have to give your database name.



?>



Registration.php



<?php

if(isset($_POST['submit']))

{

include("include/connection.php");

$a=$_POST["name"];

$b=$_POST["email"];

$c=$_POST["password"];

$d=$_POST["country"];

$e=$_POST["state"];



$query=mysql_query("insert into reg (name,email,password,country,state)

values ('”.$a.”','”.$b.”','”.$c.”','”.$d.”','”.$e.”')")or

die(mysql_error());



if($query)

{

echo "ok inserted";

}

else

{

echo "wrong";

}}

?>





This is the related html coding



<form action="" method="post"name="form">

<table width="200" border="0">

  <tr>

    <td>name:</td>

    <td><label>

      <input type="text"name="name">

    </label></td>

  </tr>

  <tr>

    <td>email:</td>

    <td><label>

      <input type="text"name="email">

    </label></td>

  </tr>

  <tr>

    <td>password:</td>

    <td><label>

      <input type="password"name="password">

    </label></td>

  </tr>

  <tr>

    <td>country:</td>

    <td><label>

      <select name="country">

 <option>india   </option>

<option>pakistan  </option>

 <option>china   </option>

 <option>

russia   </option>

 <option>england   </option>

 <option>bhutan   </option>

 <option>

 nepal   </option>

      </select>

    </label></td>

  </tr>

  <tr>

    <td>state:</td>

    <td><label>

      <select name="state">

 <option>

 haryana   </option>

 <option>

 bihar   </option>

        </select>

    </label></td>

  </tr>

  <tr>

<td>

</td><td>

      <input type="submit"name="submit" value="Submit">

    </label></td>

  </tr>

  <tr>

  <td>  </td>

  </tr>



</table></form>



Login.php



 <formaction="login_check.php"method="POST">

   USERNAME:<input type="text"name="name"><br />

   Password:<input type="password"name="password" ><br />

   <input type="submit" name="submit" value="LOG IN">

</form>



Then create the

login_check.php page as below



<?php

include 'connectionphp';

$name=$_POST['name'];

$password=$_POST['password'];

$sql="SELECT * FROM reg WHERE  name='$name'and password='$password'";

$result=mysql_query($sql);

$count=mysql_num_rows($result);

if($count==1)

{

echo “login successfully”;

}

else{

    echo "Wrong Username or Password";

}

?>

Related Questions