0

Hello,

I am stucked while making code in PHP.
I actually want to make a table in database with name as username (of the respective user).
(table should be formed only when no such table exisit before)

I used session to get username and every thing is right except formation of table... help me

session_start();
$tabname =  $_SESSION['username'];

$s1 =  sprintf("select * from '$tabname'" );
$result = mysql_query($s1);

if(!$result) 
{
$s2 = "CREATE TABLE '$tabname' (ID int NOT NULL AUTO_INCREMENT, PRIMARY KEY(ID),input varchar(50))";
mysql_query( $s2 );
}
3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by diafol
0

Try this.

session_start();
$tabname =  $_SESSION['username'];

$s1 =  sprintf("select * from '$tabname'" );
$result = mysql_query($s1);

if(!$result) 
{
$s2 = "CREATE TABLE '"$tabname"'(id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), input VARCHAR(50))" or die(mysql_error());
mysql_query( $s2 );
}
0

Not trying to be awkward, but do you really need to create a table for every user? 99.99% of the time, there is a far better solution. A users table should suffice with related tables for specific user data.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.