SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Feb 2002
    Location
    Reykjavik, Iceland
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Inserting a new poll in Mysql??

    Would someone be nice to help me with this poll ? =)


    Im developing a little POll for my site

    Im done with the script that calculates and view the poll and the "vote" insert query and now im struggling with the NEW POLL query, how i insert a new poll in the database.

    I have the poll in 3 tables

    The questions itself are stored in a table called "poll_questions"

    that contain

    ID auto inchrement
    writer_id
    question

    and another table for "possibilites"

    ID
    ID_question << this contains the id of the question
    possibilites

    And now im gonna see how one poll qould look like in this tables

    The question is "Does this question mean im total idiot"?

    and the possibilities are yes,no,youre ok..

    The poll_question

    ID [6]
    writer_id [0585] << whatever!
    question [Does this question mean im total idiot]

    and the possibilites table would be

    ID [798]
    ID_question [6]
    possibilite [yes]

    ID [799]
    ID_question [6]
    possibilite [no]

    ID [800]
    ID_question [6]
    possibilite [youre ok..]

    I also have another table for answears but that is no need to show that..


    And what query would i have to have to insert this new poll into this database?

    In the form page would the input form that has the name "pollquiz" and the possibilities input boxes that are up to 5 has name name answear1,answear2,answear3,answear5


    Could somone give me a taste of the code that would insert this new poll into this tables in database?

    That would be greatly appreciate?

  2. #2
    Action! filmfoto's Avatar
    Join Date
    Dec 2001
    Location
    Sweden
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If I understand you correctly try this:
    PHP Code:
    mysql_query("INSERT INTO poll_questions SET writer_id=$writer_id, question='$question'");

    $ques_id mysql_insert_id();

    for (
    $i 0$i sizeof($answear); $i++) {
        
    mysql_query("INSERT INTO possibilites SET ID_question=$ques_id, possibilites='$answear[$i]'");

    Your ID fields have to be AUTO_INCREMENT and change your form so the answer fields return an array on POST, name="answear[]".



    Hopes this helps.





    Cheers.


Bookmarks

Posting Permissions

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