Ask Experts Questions for FREE Help !
Ask
    leenakrishna's Avatar
    leenakrishna Posts: 4, Reputation: 1
    New Member
     
    #1

    Dec 25, 2008, 09:01 PM
    Authentication in PHP
    Hai,

    I'am ne wto PHP and I am doing a project.I want a login,in such a way that each one entered should be identified (i.e,whether the entered person is a client or admin )and they should be directed to their respective pages.What is the code I have to use.anybody there to help me...
    shihan's Avatar
    shihan Posts: 2, Reputation: 1
    New Member
     
    #2

    May 4, 2009, 05:04 AM

    I write this script and I also create the database.But it show an error.why

    <?php
    $con=mysql_connect("localhost","root");
    if(!$con){
    die('could not connect:'.mysql_error());
    }

    mysql_select_db("project",$con);

    $sql="INSERT INTO customer(firstname)
    VALUES ('$_POST[firstname]'';')";

    if(!mysql_query($sql,$con));
    {
    die('Error.'.mysql_error());
    }

    echo"1 record added";
    mysql_close($con)

    ?>
    leenakrishna's Avatar
    leenakrishna Posts: 4, Reputation: 1
    New Member
     
    #3

    May 8, 2009, 10:22 PM
    Try this:

    First one is the html form:
    <form action="newphp.php" method="post">
    Firstname: <input type="text" name="firstname" />
    Lastname: <input type="text" name="lastname" />
    Age: <input type="text" name="age" />
    <input type="submit" />
    </form>

    Following is the php code:"newphp.php".Here I have used my own database and table.Just change it.

    <?php

    $con = mysql_connect("localhost","root","");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }mysql_select_db("hai", $con);
    $sql="INSERT INTO persons (FirstName)
    VALUES('$_POST[firstname]')";
    if (!mysql_query($sql,$con))
    {
    die('Error: ' . mysql_error());
    }
    echo "1 record added";mysql_close($con)




    ?>
    slapshot_oi's Avatar
    slapshot_oi Posts: 1,537, Reputation: 589
    Ultra Member
     
    #4

    Jul 21, 2009, 07:49 PM
    Quote Originally Posted by leenakrishna View Post
    hai,

    I'am ne wto PHP and iam doing a project.I want a login,in such a way that each one entered should be identified (i.e,whether the entered person is a client or admin )and they should be directed to their respective pages.What is the code i have to use.anybody there to help me.....
    I realize this is an old thread and you may have already found the answer, but the most general answer I can give--because I'm not going to code it for you--is you have to use sessions with the $_SESSION array. To identify the group ID of the user, you have to use a database.

    You'll first have to check if a session is already started, and if not, prompt the user to login and check their input against the corresponding record in the database. If it chechks out, start a session with session_start()

    The easiset way to do all of this is use RAD tool. This code is so commonly used, you'd just be reinventing the wheel if you were to write it on your own. I use CodeCharge Studio, they have templates that do all of the generic stuff for you, you just add the special code where need be. And if you can't do that, search Google Code for snippets, I guarantee you'll find what you're looking for.

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

John Singer Sargent painting, authentication expert [ 2 Answers ]

Where can I find an expert (or committee) that can review images of a painting that I own to determine if it could be one of Sargent's "lost" paintings that he created somewhere in the Middle East in the late 19th or early 20th century? I wish to do this very discreetly because of the potential...

Apache User Authentication issue.please help [ 6 Answers ]

I'm trying to restrict access to a directory on my apache webserver. Before I go into detail I'll show what I've got so far. I've successfully created the Password file. Here's the code in httpd.conf DocumentRoot "C:/Program Files/Apache Group/Apache2/htdocs" ... ... <Directory />


View more questions Search