1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: MySQL Help

Discussion in 'Web Design & Development' started by lumentec, Sep 19, 2008.

Thread Status:
Not open for further replies.
  1. lumentec

    lumentec Thread Starter

    Joined:
    Mar 23, 2008
    Messages:
    103
    All I want to do is create a table called "turns" with columns.. "username", and "turns". I already have a database set up via CPanel... but somehow, I managed to mess it up. Some help please?

    HTML:
    <?php
    $con = mysql_connect("localhost","game","password");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    
    mysql_select_db("game", $con);
    $sql = "CREATE TABLE turns 
    (
    username varchar(16),
    turns varchar(4),
    )";
    mysql_query($sql,$con);
    
    mysql_close($con);
    ?>
     
  2. TheRobatron

    TheRobatron

    Joined:
    Oct 25, 2007
    Messages:
    551
    This is the SQL I got using PHPMyAdmin to create the table:
    Code:
    CREATE TABLE `turns` (
    `username` VARCHAR( 16 ) NOT NULL ,
    `turns` VARCHAR( 4 ) NOT NULL
    ) ENGINE = MYISAM ;
    
    The rest of your PHP looks fine so maybe it's something to do with the NOT NULL or engine (I'm not an expert on MySQL so I couldn't say). Also do you know when it fails? Is it failing to connect or to execute the query? I'd add
    PHP:
    if (!mysql_query($sql$con)) {
    die(
    "Could not execute query");
    }
    to debug it.

    HTH
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/751465

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice