Jump to content

table not being inserted into database


daniel0816

Recommended Posts

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 connection
if ($connect){
 echo "Connected";
}else{
 echo "Problem";
 }

//select database
mysql_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);
  }

?>

Link to comment
https://forums.phpfreaks.com/topic/281160-table-not-being-inserted-into-database/
Share on other sites

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 22
Error creating table:

 

Any ideas as to what the problem is:

 

Thanks

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.