Connecting Tech Pros Worldwide Help | Site Map

Creating a Table

Newbie
 
Join Date: Sep 2009
Posts: 18
#1: Oct 2 '09
Below is my code. It does not seem to be working. What am I missing? I am trying to create a database table via PHP. It yields a website cannot display the page when run. When I remove the mysql_query portion I get a Error: Query was empty, so I know it is at least doing something.


Expand|Select|Wrap|Line Numbers
  1. <?php
  2. include("input_cl.php");
  3. @mysql_connect("localhost","?????","?????");
  4. if (!@mysql_connect)
  5.   {
  6.   die('Could not connect: ' . mysql_error());
  7.   }
  8.  
  9. mysql_select_db("inv");
  10.  
  11. mysql_query("CREATE TABLE order(
  12. id INT NOT NULL AUTO_INCREMENT, 
  13. ADHDFU VARCHAR(30), PRIMARY KEY(id))";
  14.  
  15. if (!mysql_query($sql))
  16.   {
  17.   die('Error: ' . mysql_error());
  18.   }
  19. echo "Table Created!";
  20.  
  21. mysql_close()
  22. ?>
dlite922's Avatar
Expert
 
Join Date: Dec 2007
Location: Moon, Dark Side
Posts: 1,094
#2: Oct 2 '09

re: Creating a Table


Remove the @ sign and see if you get any other errors.


Dan
Newbie
 
Join Date: Aug 2008
Posts: 11
#3: Oct 2 '09

re: Creating a Table


First thing I see is you're calling mysql_query twice, once with the query as an argument, and a second time with an undefined variable $sql as the argument. I think you probably meant something like
Expand|Select|Wrap|Line Numbers
  1. $query = "CREATE TABLE etc.";
  2. if(!mysql_query($query)){
  3. //error reporting goes here
  4. }else{
  5. //success!
  6. }
Best of luck
Reply