Jump to content

[SOLVED] Naming table with user input


NightFalcon90909

Recommended Posts

Hey, this is a simple question. I searched the forum and the manuals and whatnot, and I'm sure its a simple answer, but I didn't find it anywhere. So if anyone had a free moment, I'd really appreciate it.

 

Essentially, my science fair project is making a web based personal password generator/manager. I want to be able to store passwords in a table.

 

I created a user with all privileges to a database called BetterPass. I successfully connected with that user to the BetterPass db.

 

Know I would like to create a table, which should be named whatever my username is.

 

Let $username = the desired username of the table.

 

$query = 'CREATE TABLE $username (
...
);

 

creates a database name "$username", not the actual username. The question then, how can I get that table to be named whatever $username points to, and not actually "$username"?

 

Thanks so much for your time!

Link to comment
https://forums.phpfreaks.com/topic/142275-solved-naming-table-with-user-input/
Share on other sites

single quotes do not parse variables.  Double quotes will.

 

$name = 'blah';
echo '$name'; // output: $name
echo "$name"; // output: blah

 

alternatively, you can jump in and out of the quotes to have php parse the var outside of the quote:

 

$name = 'mud';
echo 'my name is ' . $name . ' i am blue'; // output: my name is mud i am blue

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.