Free2Code
Tutorials » Browse » PHP
Tutorials - Creating a PHP Login Script - Creating the table
This article written by
  OldSite

Member since
  October 11, 2006

Now we need to design the database, I am providing a script that will create this table for you.

File: table.php
<?php

require 'db_connect.php';

// require above script
// change the path to match wherever you put it.

$table = "CREATE TABLE users (
id int(10) DEFAULT '0' NOT NULL auto_increment, 
username varchar(40),
password varchar(50), 
regdate varchar(20),
email varchar(100),
website varchar(150),
location varchar(150),
show_email int(2) DEFAULT '0',
last_login varchar(20),
PRIMARY KEY(id))";

$create = $db_object->query($table);    //perform query

if(DB::isError($create)) {
    die($create->getMessage());
} else {
    echo 'Table created successfully.';

}

$db_object->disconnect();

?>

That script will create a table in the database you specified, once you have executed this script you can take it out of your document tree so others cannot run it.

You could also run the following database query in something like PHPMyAdmin:

CREATE TABLE users (
id int(10) DEFAULT '0' NOT NULL auto_increment, 
username varchar(40),
password varchar(50), 
regdate varchar(20),
email varchar(100),
website varchar(150),
location varchar(150),
show_email int(2) DEFAULT '0',
last_login varchar(20),
PRIMARY KEY(id))

We will use this table to store user information, retrieve it and check it. Now we need to allow users to become members.


Continue to Sign Up »
In this tutorial:
  1. Introduction
  2. Connecting to the database
  3. Creating the table
  4. Sign Up
  5. Check if they are "logged in"
  6. Allow them to 'log in'
  7. Usage
  8. Conclusion
Penguino AVR

Want to learn about robotics or microcontrollers?
Check out the Penguino AVR from our friends at
Icy Labs