Help with submitting form data

Discussion in 'MySQL' started by jawinn, Nov 13, 2006.

  1. #1
    I have a user registration form that submits to MySQL. The user form collects info in this order:

    id
    name
    email
    state
    zip
    cookid

    $query1="INSERT INTO members(name,email,city,state,zip,cookid) VALUES('$_POST[name]','$_POST[email]','$_POST[city]','$_POST[state]','$_POST[zip]','$cookid')";
    Code (markup):
    I want to be able to have the DB table look like this:
    id
    name
    attribute1
    email
    state
    zip
    cookid

    The question becomes how do I submit the top set of information and not have it in the wrong fields in the DB? Is there some sort of null value i have to add to the string?

    thx
     
    jawinn, Nov 13, 2006 IP
  2. maiahost

    maiahost Guest

    Messages:
    664
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Since you only insert it in the name,email,city,state,zip,cookid fields the attribute1 will be left blank or the dafault value.
     
    maiahost, Nov 13, 2006 IP
  3. ThomasNederman

    ThomasNederman Peon

    Messages:
    112
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    The ID field works best if you declare it as " int(11) NOT NULL auto_increment", you need to declare it as " PRIMARY KEY (ID)" in order for it to increase .

    If you like to avoide null you could use "varchar(50) NOT NULL default 'test'" to avoide null in database

    Hope this help a bit
     
    ThomasNederman, Nov 14, 2006 IP
  4. j0ned

    j0ned Active Member

    Messages:
    684
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    60
    #4
    If you don't include attribute1 on your form, the value will be blank or filled with whatever is in your insert command. Also, you should set your 'id' field as the primary key & to auto increment. That will prevent you from having to look up the previous records number and manually setting the id. I also discovered it helps to set unique ID names for each table.

    cust_id
    prod_id
    user_id

    etc... don't use 'rowid' or 'id' etc.. you'll get confused (at least I did :-/)
     
    j0ned, Nov 14, 2006 IP