0
我想插入到mySql表中,表名是sql select查询的结果,第一个查询返回正确的结果,但第二个查询是where错误似乎是谎言,任何帮助将非常非常感谢PHP - 插入表与前面的select语句结果的名称
$query = mysql_query("SELECT council from users where username = '$username'");
$x = mysql_result($query,0, "council");
$councilArea = (string)$x;
// mysql inserting a new row
$result = mysql_query("INSERT INTO '$councilArea' ('barcode', 'productname', 'bin', 'info', 'addedby') VALUES('$barcode', '$productname', '$bin', '$info', '$username')");
什么是错误? – NoLiver92
单引号''councilArea''和所有列名称如'barcode''的错误结果请参阅http://stackoverflow.com/questions/11321491/when-to-use-single-quotes-double -quotes-和反引号。不应该引用表和列名(除非它们是保留字,需要反引号) –
但是这也指出了数据库设计中的一个更大的问题。而不是存储保存相关信息的表的_name_,而应该将列存储在作为外键的单个表中。换句话说,您的设计意味着您应该有一个带有区分列的表,并且您可以执行连接查询时有几个类似的表。 –