时间:2021-07-01 10:21:17 帮助过:2人阅读
$tableName = 'member';
mysql_query("insert into".$tableName." values ()");
$tableName = 'member';
mysql_query("insert into".$tableName." values ()");
例如,每个用户都在注册的时候同时生成了一个相应的数据表,那等一个0101的用户登录后,我把0101(既是用户名也是表名)保存到$_SESSION['msg']中,那我这样写:
$tableName=$_SESSION['msg'];
mysql_query("insert into".$tableName." (id,name,telephone) values('$counters[0]','$counters[1]','$counters[2]')");
为什么还有错误呢?
提示什么错误?
你用session之前
session_start();了?
mysql_query("insert into ".$tableName." (id,name,telephone) values ('$counters[0]','$counters[1]','$counters[2]')");
打印你的sql,看输出什么东西
mysql_query("insert into ".$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 ''0101' (id,name,telephone)values('?1','王刚','19011224442 ')' at line 1
session_start();也写了
表名不用加单引号 直接输出sql语句看下就知道错在那了
打印你的sql,看输出什么东西
输出:insert into '0101' (id,name,telephone)values('?1','王刚','19011224442 ')
mysql_query("insert into `$tableName` (id,name,telephone) values ('$counters[0]','$counters[1]','$counters[2]')");
表名不用加单引号 直接输出sql语句看下就知道错在那了
谢谢你,按照你说的们果然调试出来了,
$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]