Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Dec 2005
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts

    creating table on registration

    UPDATE: PROBLEM SOLVED!

    i have a login system but upon registration i want to create a table withing database for the user :

    PHP Code:
      else {
              
    mysql_query("INSERT INTO user (user, pword, level) VALUES ('$name','$pword', '1')"); 
       
    mysql_query("CREATE TABLE '$user' ( id int(10) NOT NULL,name varchar(26) NOT NULL default,ad varchar(100) NOT NULL default,  
    PRIMARY KEY (id) )"
    )  ;
            } 
    i can create a table upon registration but its the same table each time. ie. CREATE TABLE name....

    but i want a new table to be created each time, and '$user' does not work.... i want a table named after the username on registration to be create that they can use while logged in to store key data
    Last edited by kaiiak; 01-02-2006 at 02:48 PM.

  • #2
    Senior Coder
    Join Date
    Apr 2005
    Location
    Colorado, United States
    Posts
    1,208
    Thanks
    0
    Thanked 0 Times in 0 Posts
    First, is $user even set? Second, why create an entire table for just a user? Store all the users in a single table, and the key data for all users in another table with a column for the user id.
    "$question = ( to() ) ? be() : ~be();"

  • #3
    New Coder
    Join Date
    Dec 2005
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts
    UPDATE

    i have a list of all users... already

    but i want each user to have their own table for a specific purpose on website...

    i can create the '$user' different tables now....

    but need to be able to reference to it on other pages of website....

    should i create session variables or summit.... how do i specify the same variable for another page so it inputs to their specific table..?....

    i can create table of ".$name." where name is the username on registration...

  • #4
    Senior Coder
    Join Date
    Apr 2005
    Location
    Colorado, United States
    Posts
    1,208
    Thanks
    0
    Thanked 0 Times in 0 Posts
    But why create potentially thousands of tables when you can use a single table with the data in another table (or tables, if you wish to categorize it), and simply add their user id in a column of that table? Not to mention you risk the table name conflicting with your already existing tables unless you prefix them, but even then, its a rather dirty solution. And yes, session variables would be a good way to carry user ids/names (always use user ids to reference a user) from page to page.
    "$question = ( to() ) ? be() : ~be();"

  • #5
    New Coder
    Join Date
    Dec 2005
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i have used this upon login.php
    PHP Code:
    session_start(  );
    $user $_SESSION['username'] = $name
    how would i refer to the variable $name in another page of website.....

    UPDATE: i can get it to print out users name on another page but not to actual use that name to call their table:

    PHP Code:
    echo "Welcome, ".$user."<br>"// Welcome message
    $mysql_query "INSERT INTO '$user' VALUES ('','$name','$ad')"
    table exists but nothing is entered
    Last edited by kaiiak; 01-02-2006 at 01:04 PM.

  • #6
    Regular Coder ralph l mayo's Avatar
    Join Date
    Nov 2005
    Posts
    951
    Thanks
    1
    Thanked 31 Times in 29 Posts
    Quote Originally Posted by kaiiak
    i have used this upon login.php
    PHP Code:
    session_start(  );
    $user $_SESSION['username'] = $name
    What's going on here? Looks like $_SESSION['username'] is being assigned the value (null, unless it's specified somewhere before this?) of $name, and then the value is propagated to $user, which doesn't make a whole lot of sense.

    Is this line supposed to read the value of the session or set it?

    Quote Originally Posted by kaiiak
    UPDATE: i can get it to print out users name on another page but not to actual use that name to call their table:

    PHP Code:
    echo "Welcome, ".$user."<br>"// Welcome message
    $mysql_query "INSERT INTO '$user' VALUES ('','$name','$ad')"
    table exists but nothing is entered
    Typically, just use $_SESSION['username'] again, because it's a superglobal and hence equally available to all pages. Consider using mysql_real_escape_string() to keep your tables safe from hostile or badly formed user data. Ie:

    PHP Code:
    $name mysql_real_escape_string($_SESSION['name']); // prevents SQL sensitive chars like ' from messing up statements by escaping them
    echo stripslashes($name); // return to unescaped version for display 
    As Velox said, creating a per user table isn't really such a hot idea, but it probably won't matter unless you start getting a lot of traffic.


  •  

    Posting Permissions

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