Mysql "insert table name ......" Can table names make variables? Mysql "insert table name ......" Can table names make variables? How to implement it?
Reply to discussion (solution)
$ TableName = 'member ';
Mysql_query ("insert into". $ tableName. "values ()");
$ TableName = 'member ';
Mysql_query ("insert into". $ tableName. "values ()");
For example, each user generates a corresponding data table at the same time during registration. after a 0101 user logs on, I set 0101 (both the user name and the table name) save it to $ _ SESSION ['MSG ']. then I write it like this:
$ TableName = $ _ SESSION ['MSG '];
Mysql_query ("insert ". $ tableName. "(id, name, telephone) values ('$ counters [0]', '$ counters [1]', '$ counters [2]')");
Why are there errors?
What error is prompted?
Before you use session
Session_start?
Mysql_query ("insert ". $ tableName. "(id, name, telephone) values ('$ counters [0]', '$ counters [1]', '$ counters [2]')");
Print your SQL to see what is output
Mysql_query ("insert ". $ tableName. "(id, name, telephone) values ('$ counters [0]', '$ counters [1]', '$ counters [2]')");
Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '000000' (id, name, telephone) values ('? 1 ', 'Wang gang', '123')' at line 1
Session_start ();
The table name does not need to be enclosed in single quotes and the SQL statement can be output directly.
Print your SQL to see what is output
Output: insert into '000000' (id, name, telephone) values ('? 1 ', 'Wang gang', '123 ')
mysql_query("insert into `$tableName` (id,name,telephone) values ('$counters[0]','$counters[1]','$counters[2]')");
The table name does not need to be enclosed in single quotes and the SQL statement can be output directly.
Thank you. according to what you said, the debugging was completed,
$ TableName = $ _ SESSION ['MSG '];
$ SQL = mysql_query ('set names utf8 ');
Mysql_query ($ SQL );
$ SQL = "insert into $ tableName (id, name, telephone) values ('$ counters [0]', '$ counters [1]', '$ counters [2]') ";
[Img = http://forum.csdn.net/PointForum/ui/scripts/csdn/Plugin/001/face/12.gif "] [/img]