daniel0816 Posted August 14, 2013 Share Posted August 14, 2013 (edited) Hi I am trying to insert a table a table into the database. I am connecting to the database ok but its not creating the table it just keeps displaying the echo which I have set in order to check that the table is created so in this case its saying error creating table. I have checked my code countless times but still cant find the problem any help would be greatly appreciated thanks. <?php$connect = mysql_connect("database info goes here");//check connectionif ($connect){ echo "Connected";}else{ echo "Problem"; } //select databasemysql_select_db("dbname", $connect); // Create table $sql="CREATE TABLE test( TestID int AUTO_INCREMENT NOT NULL, name varchar(30), PRIMARY KEY(TestID) )"; // Execute query if (mysql_query($connect,$sql)) { echo "Table Customers created successfully"; }else { echo "Error creating table: " . mysql_error($connect); } ?> Edited August 14, 2013 by daniel0816 Quote Link to comment Share on other sites More sharing options...
PravinS Posted August 14, 2013 Share Posted August 14, 2013 (edited) write error_reporting(E_ALL) at the top, so it will display errors if any also check whether your database user is having CREATE previlege Edited August 14, 2013 by PravinS Quote Link to comment Share on other sites More sharing options...
daniel0816 Posted August 14, 2013 Author Share Posted August 14, 2013 (edited) Sorry it is displaying the following error: Warning: mysql_query() expects parameter 1 to be string, resource given in /homepages/18/d228326958/htdocs/suppmytek/tablesdb.php on line 22Error creating table: Any ideas as to what the problem is: Thanks Edited August 14, 2013 by daniel0816 Quote Link to comment Share on other sites More sharing options...
mikosiko Posted August 14, 2013 Share Posted August 14, 2013 read carefully the "Description:" for the mysql_query() function. http://php.net/manual/en/function.mysql-query.php P.S.: Not related with your issue, but pay attention too to the big "Warning" at the beginning. Quote Link to comment Share on other sites More sharing options...
Solution daniel0816 Posted August 14, 2013 Author Solution Share Posted August 14, 2013 Its ok I've fixed the problem thanks for your help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.