Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,042
    Thanks
    19
    Thanked 42 Times in 42 Posts

    Question SQL create table?

    Code:
    `username` varchar(30) NOT NULL ,
      `password` varchar(30) NOT NULL '',
      `name` varchar NOT NULL,
      `surname` varchar(30) NOT NULL,
      `email` varchar(30) NOT NULL ,
      PRIMARY KEY  (`username`)
    should i be using tinytext i read the post on how to choose field types and got confused, does VARCHAR(30) have to be 30 chars long? and i cannot seem to create a table with the following code! any help?
    Code:
    mysql_query("CREATE TABLE users(
    `username` varchar(30) NOT NULL ,
      `password` varchar(30) NOT NULL '',
      `name` varchar NOT NULL,
      `surname` varchar(30) NOT NULL,
      `email` varchar(30) NOT NULL ,
      PRIMARY KEY  (`username`)) )";

  • #2
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,631
    Thanks
    4
    Thanked 147 Times in 138 Posts
    the error is the ' ' after the password field. Why have a field be NOT NULL if you are going to allow it to have a blank field as the default?

    Also when you set a default you need to specify it like this:

    password varchar(30) NOT NULL DEFAULT ' '

    but again, I'd not have a default of ' '

    also in my opinion, make it 40 characters and look into the use of SHA1 for hashing your passwords.

  • #3
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,042
    Thanks
    19
    Thanked 42 Times in 42 Posts
    Code:
    mysql_query("CREATE TABLE users(
    `username` varchar(30) NOT NULL,
      `password` varchar(40) NOT NULL,
      `name` varchar NOT NULL,
      `surname` varchar(30) NOT NULL,
      `email` varchar(30) NOT NULL,
      PRIMARY KEY  (`username`)) )";
    so that should and i quote SHOULD create a mysql table called users
    this gave me the error

    Parse error: parse error, unexpected ';' in /home/www/rafiki.freehostia.com/jamiewestrunonce.php on line 11
    Last edited by rafiki; 03-08-2007 at 07:46 PM.

  • #4
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    Quote Originally Posted by rafiki View Post
    PHP Code:
    mysql_query("CREATE TABLE users(
    `username` varchar(30) NOT NULL,
      `password` varchar(40) NOT NULL,
      `name` varchar NOT NULL,
      `surname` varchar(30) NOT NULL,
      `email` varchar(30) NOT NULL,
      PRIMARY KEY  (`username`)) )"

    so that should and i quote SHOULD create a mysql table called users
    this gave me the error

    Parse error: parse error, unexpected ';' in /home/www/rafiki.freehostia.com/jamiewestrunonce.php on line 11
    using an editor with syntax highlighting should have caught that
    PHP Code:
    mysql_query("CREATE TABLE users(
    `username` varchar(30) NOT NULL,
      `password` varchar(40) NOT NULL,
      `name` varchar NOT NULL,
      `surname` varchar(30) NOT NULL,
      `email` varchar(30) NOT NULL,
      PRIMARY KEY  (`username`))"
    ); 

  • #5
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,631
    Thanks
    4
    Thanked 147 Times in 138 Posts
    if you ask me, use something like PHPMYADMIN or HEIDI SQL to create your tables and don't rely on wrapping your sql code in php and making simple syntax errors that have nothing to do with your sql.

  • #6
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,042
    Thanks
    19
    Thanked 42 Times in 42 Posts
    my host is freehostia.com (using free host) i dont think i have PHPMYADMIN for an option but and i use standard notepad.exe free with windows. Also im waiting for a few parts to come before my "real" pc is up and running, this isnt worth installing a syntax highlighting editor on
    but thanks for the help

    also i ran the page it said the table hd been created, i get this error

    Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/www/rafiki.freehostia.com/register.php on line 34
    Table '***********.users' doesn't exist
    Last edited by rafiki; 03-08-2007 at 11:18 PM.

  • #7
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,631
    Thanks
    4
    Thanked 147 Times in 138 Posts
    Download EditPlus or some other editor that will highlight your syntax.

    also note that when posting here you can wrap your php in these tags [ php] and [/php] without the space in the first tag. that will show you the highlighting as well.

    how are you interfacing mysql do you have direct access to it? you should NOT be using php, perl or anything else if you do not have to UNTIL you know that your queries are working correctly. At that point then introduce your application code. Then you will know if the error is mysql or other code related.

  • #8
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,042
    Thanks
    19
    Thanked 42 Times in 42 Posts
    Quote Originally Posted by guelphdad View Post
    also note that when posting here you can wrap your php in these tags [ php] and [/php] without the space in the first tag. that will show you the highlighting as well.

    how are you interfacing mysql do you have direct access to it? you should NOT be using php, perl or anything else if you do not have to UNTIL you know that your queries are working correctly
    currently i am accessing and querying the databse threw PHP as far as i know its the only way with freehostia's free package, and i do know about the php tags for colour syntax but i didnt think it would matter, in future i will use colour highlighting editors is the one you mentioned free?

  • #9
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    You can also use scite (www.scintilla.org) I've used it for years and is free

  • #10
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,042
    Thanks
    19
    Thanked 42 Times in 42 Posts
    Quote Originally Posted by Nightfire View Post
    You can also use scite (www.scintilla.org) I've used it for years and is free
    it says i need a compiler and stuff :/ sorry not for me, this is my spare (real old) pc and looking for .exe to just run and install for me

  • #11
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,631
    Thanks
    4
    Thanked 147 Times in 138 Posts
    editplus is free and will install simply. and the tags used here at codingforum are even simpler and will also show your syntax errors.

  • #12
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    http://scintilla.sourceforge.net/SciTEDownload.html includes a link to a windows executable...

    (this was linked to from the previous url)
    My thoughts on some things: http://codemeetsmusic.com
    And my scrapbook of cool things: http://gjones.tumblr.com

  • #13
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,042
    Thanks
    19
    Thanked 42 Times in 42 Posts
    Quote Originally Posted by GJay View Post
    http://scintilla.sourceforge.net/SciTEDownload.html includes a link to a windows executable...

    (this was linked to from the previous url)
    i only managed to find the zip file, also if i just used the php tags here on cf, i would be classed as a spammer right? or are u saying make the thread then delete it :s

  • #14
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts

  • #15
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,631
    Thanks
    4
    Thanked 147 Times in 138 Posts
    Quote Originally Posted by rafiki View Post
    i only managed to find the zip file, also if i just used the php tags here on cf, i would be classed as a spammer right? or are u saying make the thread then delete it :s
    NO, I'm saying if you have a problem and you post it here and leave it as is but use the php tags you will see the syntax.

    Though I'm not sure why you are hesitant to download editplus to your machine.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •