Jump to content

table not being inserted into database


Go to solution Solved by 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);
  }

?>

Edited by daniel0816
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

Edited by daniel0816
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.