2 Replies Latest reply on Nov 23, 2007 1:53 PM by (Sofus_Comer)

    How can i get the login info on a table

      i am using my sql data base.people who are visiing my web site can log in to the sites restricted areas using their Usernames and Passwords. (the login is based on the "Register" table in the data base)

      When somebody enteres the site using their Username and Password, and inputs new data to anothertable (classified table), How can the classified table get the login Username to one of its columns. (automatically Username of the user is added to the table)

      how can i do that. A coding for that would e perfect. please help me. i would be really greatful to you.


        • 1. Re: How can i get the login info on a table
          The easiest way would be to set a SESSION of the username, and then insert the contents of that SESSION into the classified table's username field. You need to register a SESSION on every page of your site by placing <?php session_start(); ?> at the top of every page (in code view). This must be the very first line of code. Using SESSIONS is very handy because it stores any information that you want in a cookie - except that this is stored on the server (not the user's hard drive) and is destroyed when the user quits the browser. <br /> <br />Here's a couple of different ways to get you started <br /> <br /> <code> <br /><?php session_start(); ?> <br /><?php require_once('Connections/conn.php'); ?> <br /><?php<br /> // check to see if the username session is set<br><br /> if(!isset($_SESSION['username'])) {<br />  // it's not, register the username session<br />  $_SESSION['username'] = $username;<br /> }<br /> <br /> // or grab the username from the $_POST of the login form<br /> $username = trim($_POST['username']);<br /> $_SESSION['username'] = $username;<br /> <br /> // insert into classifieds table<br /> $sql = mysql_query("INSERT INTO classifieds (username) VALUES('".$_SESSION['username']."')") or die(mysql_error());<br />?> <br /> </code>
          • 2. Re: How can i get the login info on a table
            Hi Sisira
            When you start making a site and wish to have login etc.
            Start by going to the Control Panel in the top tab of Developer Toolbox.

            Choose the Login Settings (Box with a key)
            Take one TAB at a time.

            When you get to TAB 3, carefully follow the settings for the session,
            Its in here you get to select which session data you want to use for later.
            Examples of very cool SESSION data to use later. IF they arent allready there.


            Finally ADDT does offer a bit of tracking
            When you click the 6th TAB (History)
            You may set up some log in info to a mysql table.

            I made mine like this. !!! (Remember to create the table before you start running thru the Login Setup, and you may have to reset database cache to see it.

            CREATE TABLE `login_stats` (
            `ID_login_stats` int(30) NOT NULL auto_increment,
            `ID_usr_login_stats` int(11) NOT NULL default '0',
            `IP_log` varchar(16) NOT NULL default '',
            `last_login` datetime NOT NULL default '0000-00-00 00:00:00',
            `last_activity` datetime NOT NULL default '0000-00-00 00:00:00',
            `session_data` varchar(100) NOT NULL default '',
            PRIMARY KEY (`ID_login_stats`)
            ) TYPE=MyISAM AUTO_INCREMENT=1 ;

            I know its a bit jumpy, but i am also a bit hammered.
            Good luck.