dousha4804 2013-12-01 11:20
浏览 13
已采纳

PHP创建了mysql表,但也给出了“Table not created”错误

I have the following script to create tables in a mysql database

$dbhost = 'localhost';
$dbuser = 'root';
$con = "mysql_connect($dbhost, $dbuser, '')";
$create=mysql_query("CREATE TABLE `$table_name` (ID int NOT NULL AUTO_INCREMENT KEY,high TEXT ,low TEXT ,Divergence TEXT ,Change_Percent TEXT ,Low_Price TEXT ,High_Price TEXT ,Low_Proximity TEXT ,Vol_Index TEXT ,Vol TEXT ,Purchase_Value TEXT)");

                    if (mysql_query($con,$create))
                        {
                        echo "Table created successfully";
                        }
                    else
                        {
                        echo "Error creating table: " . mysql_error($conn);
                        }

Executing the script does create an the desired table, however it also gives the following error

Warning: mysql_query() expects parameter 2 to be resource, boolean given in C:\xampp\htdocs\test\test.php on line 136
Error creating table:

Now according to me this means $create returns "FALSE" which would be the case if the table was not created, however in this case the table has been created, what then is making it a Boolean? and How can I stop this error??

  • 写回答

4条回答 默认 最新

  • douzhai1182 2013-12-01 11:23
    关注

    the condition should be

                        if ($create)
                        {
                        echo "Table created successfully";
                        }
    

    u have already run the query and u are pasing again the mysql_query($con,$create)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探