...

View Full Version : creating table on registration



kaiiak
01-01-2006, 10:57 PM
UPDATE: PROBLEM SOLVED!

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



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

Velox Letum
01-02-2006, 12:06 AM
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.

kaiiak
01-02-2006, 12:10 AM
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...

Velox Letum
01-02-2006, 12:15 AM
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.

kaiiak
01-02-2006, 12:36 PM
i have used this upon login.php


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:



echo "Welcome, ".$user."<br>"; // Welcome message
$mysql_query = "INSERT INTO '$user' VALUES ('','$name','$ad')";


table exists but nothing is entered

ralph l mayo
01-02-2006, 07:00 PM
i have used this upon login.php


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?



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



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:



$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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum