SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jun 2001
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to create a table when regist....

    Hello all

    I have one registration page which allows a new user can regist himself an username and a password. These username and password will be stored into a table of a database.

    Now I want is that when that user regists himself, he also creates a data table for himself. Then each time he logs in, he can insert, delete or edit his table. Could you please tell me how to do that.....

    Normally I can use SQL with foreign key, but in MySQL, this is not supported.

    Thank you very much for help
    john

  2. #2
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    We're using PHP right? Not a problem!

    PHP Code:
    $username "Alex Stanton";
    $age 14;
    $occupation "Server Side Dev/Database Admin";
    $password "favoritenumber";

    if(
    ereg("_"$username)){
    echo(
    "No Underscores Allowed In Username");
    } else {

    $tabe_name ereg_replace(" ""_"$username);

    $sql "INSERT INTO users SET username='$username', age='$age', occupation='$occupation', password=PASSWORD('$password'), active='1'";

    if(!
    mysql_query($sql)){

    echo(
    "Database Error");

    } else {

    $sql "CREATE TABLE $table_name (id INT not null AUTO_INCREMENT, test TEXT , PRIMARY KEY (id))";

    if(!
    mysql_query($sql)){

    echo(
    "Database Error");

    } else {

    echo(
    "Thank You For Signing Up");

    }


    I hope that works! No Quarantees, because I haven't tried it, but it should. I beleive you can also delete a table the same way.

    PHP Code:

    // include.inc
    function remove_user_table($username){
    $table_name ereg_replace(" ""_"$username);

    if(!
    mysql_query(DROP TABLE $table_name)){
    return 
    false;
    } else {
    return 
    true;
    }
    }

    // modify.php
    if($action=="delete"){

    $sql "UPDATE users SET active='0' WHERE username='$username'";
    if(!
    mysql_query($sql)){
           echo(
    "Database Error");
    } else {
          if(!
    remove_user_table($username)){
               echo(
    "Database Error");
          } else {
          echo(
    "$username Successfully Deleted");
          }
    }

    "No Guarantees Expresses Or Implied To The Suitability Of This Code For Any Purpose Or Use."

    Regards,

    Alex
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

  3. #3
    SitePoint Member
    Join Date
    Jun 2001
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you very much for your help
    john


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •