/    Sign up×
Community /Pin to ProfileBookmark

using a variable to create a table name

hey all,
i racking my brains and im sure its a simple solution.
im wanting to create a table on the database using the username varible from the form and all im getting is a table named “$username”

[code=php]$query = ‘CREATE TABLE $username( ‘.
‘cid INT NOT NULL AUTO_INCREMENT, ‘.
‘username VARCHAR(45) NOT NULL,’.
‘password VARCHAR(15) NULL,’.
‘saying VARCHAR(20) NOT NULL, ‘.
‘name VARCHAR(50) NOT NULL, ‘.
‘address VARCHAR(30) NOT NULL, ‘.
‘sex TEXT NOT NULL, ‘.
‘PRIMARY KEY(cid))’;[/code]

if any one can help me out it would be great

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@chazzyApr 03.2006 — it's always good to quote your text properly

[code=php]

$query = 'CREATE TABLE '.$username.'( '.
'cid INT NOT NULL AUTO_INCREMENT, '.
'username VARCHAR(45) NOT NULL,'.
'password VARCHAR(15) NULL,'.
'saying VARCHAR(20) NOT NULL, '.
'name VARCHAR(50) NOT NULL, '.
'address VARCHAR(30) NOT NULL, '.
'sex TEXT NOT NULL, '.
'PRIMARY KEY(cid))';
[/code]
Copy linkTweet thisAlerts:
@mikeflyauthorApr 03.2006 — now i dont get anything not even my "$username" table
Copy linkTweet thisAlerts:
@chazzyApr 03.2006 — well, are you sure that $username is set before this query is set?
Copy linkTweet thisAlerts:
@mikeflyauthorApr 04.2006 — yes,

im sure because the $username creates a directroy on the server and setting up the table in the DB is my next step
Copy linkTweet thisAlerts:
@rch10007Apr 04.2006 — not sure if it will work but you can try enclosing $username like {$username}
Copy linkTweet thisAlerts:
@acemoApr 04.2006 — Getting any error?

If so what is the error you are getting?
Copy linkTweet thisAlerts:
@mikeflyauthorApr 04.2006 — no errors its acting like the code isnt even there grrrrrrr somedays i wish i had never started doing this stufff :mad:
×

Success!

Help @mikefly spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.1,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...