Creating a Table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • monion
    New Member
    • Sep 2009
    • 18

    Creating a Table

    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.


    Code:
    <?php
    include("input_cl.php");
    @mysql_connect("localhost","?????","?????");
    if (!@mysql_connect)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    mysql_select_db("inv");
    
    mysql_query("CREATE TABLE order(
    id INT NOT NULL AUTO_INCREMENT, 
    ADHDFU VARCHAR(30), PRIMARY KEY(id))";
    
    if (!mysql_query($sql))
      {
      die('Error: ' . mysql_error());
      }
    echo "Table Created!";
    
    mysql_close()
    ?>
    Last edited by Dormilich; Oct 3 '09, 07:55 AM. Reason: Please use [code] tags when posting code
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

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


    Dan

    Comment

    • thesmithman
      New Member
      • Aug 2008
      • 37

      #3
      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
      Code:
      $query = "CREATE TABLE etc.";
      if(!mysql_query($query)){
      //error reporting goes here
      }else{
      //success!
      }
      Best of luck

      Comment

      Working...