www.webdeveloper.com
Results 1 to 11 of 11

Thread: HELP Need to know how to structure MYSQL databases for CONTACT SIGNUP LOGIN HELP

  1. #1
    Join Date
    Feb 2012
    Location
    Sacramento, CA
    Posts
    64

    HELP Need to know how to structure MYSQL databases for CONTACT SIGNUP LOGIN HELP

    Don't know too much about MySQL but I have managed to create a SIGN UP form and was able to save the input to a database.

    NOW, I need to know how I should add the databases for the CONTACT FORM and LOGIN FORM.

    Should I use the same database for all the forms and just add tables?

    Should I create a separate database for all even though the sign up form and the login form use a few of the same fields? (email, password).

  2. #2
    Join Date
    Mar 2009
    Posts
    452
    use same database if you are going to implement those forms in same project. just create different tables. also there can be atleast one same field so you can identify users. for example their email address

  3. #3
    Join Date
    Feb 2012
    Location
    Sacramento, CA
    Posts
    64
    So use the same email field in all three tables?? Like the contact table will have a table named email, the login table will have a field named email, etc..

    ?

  4. #4
    Join Date
    Mar 2009
    Posts
    452
    yes, you will find it easy at this level

  5. #5
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,222
    There probably is not a one-to-one correlation between forms and DB tables. You probably want a "user" table with the info necessary to define a user, including login name and/or email address (should be unique), possibly an auto-incremented user_id to use as the primary key, then columns with any other user-specific data.

    Then your various forms that deal with user info in any manner will access that single table (read it for login authorization, insert into it to add a new login account, update to change whether or not the user wants to receive email news, etc.).
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  6. #6
    Join Date
    Feb 2012
    Location
    Sacramento, CA
    Posts
    64
    Do you guys use PHPMyAdmin? How do you duplicate a table so I can just delete/modify/add some of the fields instead of recreating the entire table from scratch again??

  7. #7
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,222
    I don't have phpMyAdmin at work (we use PostgreSQL), but you should be able to run the following from a SQL window (whatever phpMyAdmin calls it):
    Code:
    CREATE TABLE new_database.users LIKE old_database.users;
    If you then want to copy all its data, to:
    Code:
    INSERT new_database.users SELECT * FROM old_database.users;
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  8. #8
    Join Date
    Feb 2012
    Location
    Sacramento, CA
    Posts
    64
    Wow thanks, that worked like a charm!

  9. #9
    Join Date
    Feb 2012
    Location
    Sacramento, CA
    Posts
    64
    So is PostgreSQL used more in the industry? Also, how come every time I go to an interview they ask if I can do a table join? What exactly does this mean? The jobs I applied for were for entry level PHP coders.

  10. #10
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,222
    PostgreSQL and MySQL are not all that different, in general. I'm not sure why PG was specifically selected where I work, though I understand there are some subtle licensing differences that may have played a part.

    Table joins are an integral part of using a relational database. They allow you to query across multiple tables (even across multiple databases). As a simple(?) example, let's say you have "user" and "post" tables:
    Code:
    user
    ==========
    user_id (int, primary key, auto-increment)
    last_name (varchar)
    first_name (varchar)
    
    
    post
    =========
    post_id (int, primary key, auto-increment)
    user_id (int) -- indicates who did the posting
    post_timestamp (timestamp)
    title (varchar)
    post_text (text)
    Now you want to display the latest post, along with the author's name:
    Code:
    SELECT user.first_name, user.last_name, post.title, post.post_text
    FROM post
    INNER JOIN user USING(user_id)
    ORDER BY post.post_timestamp DESC
    LIMIT 1
    If that does not make sense, then it's time to start googling for tutorials and such on relational database design and normalization.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  11. #11
    Join Date
    Feb 2012
    Location
    Sacramento, CA
    Posts
    64
    I'll have to read a tutorial..

    By the way, is there an easy way for me to send the contact info stored in one of my databases to be emailed to me upon a user submitting it??

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles