PHP mysql survey

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • arty
    New Member
    • Nov 2008
    • 35

    PHP mysql survey

    I must build a survey with many question (around 50), so i cannot have the survey in just one page, i would like to have it on many pages so one user will hit submit many times, how can i make so in the database there's always one Row per user and not many rows as many submit per user?
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hey.

    You can use the UPDATE command to do that.
    Use INSERT on the first page and just UPDATE the row on the proceeding pages.

    Comment

    • arty
      New Member
      • Nov 2008
      • 35

      #3
      hi, yes but the action attribute of the form is another form so it wont complete the MSQL command:
      <form method="post" action="Q2.php" >
      looks like i need to use sessions so i do all the SQL command on the last form/page

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        What do you mean?

        You just use a different SQL query on each page...

        page1.php
        [code=php]
        <form action="page2.p hp" method="post">
        <input type="text" name="first_inf o" />
        <input type="submit" />
        </form>
        [/code]

        page2.php
        [code=php]
        <?php
        // Get the data from the last form
        $first_info = mysql_real_esca pe_string($_POS T['first_info']);

        // Insert a new row into the database
        $sql = "INSERT INTO tbl(first_info) VALUES('{$first _info}')";
        mysql_query($sq l) or trigger_error(m ysql_error(), U_USER_ERROR);

        // Get the ID of the row that was just created.
        $row_id = mysql_insert_id ();
        ?>
        <form action="page3.p hp" method="post">
        <input type="hidden" name="row_id" value="<?php echo $row_id; ?>" />
        <input type="text" name="second_in fo" />
        <input type="submit" />
        </form>
        [/code]

        page3.php
        [code=php]
        <?php
        // Get the data from the last form
        $second_info = mysql_real_esca pe_string($_POS T['second_info']);
        $row_id = mysql_real_esca pe_string($_POS T['row_id'])

        // Update the row in the database with the new info
        $sql = "UPDATE tbl
        SET second_info='{$ second_info}'
        WHERE row_id={$row_id }
        LIMIT 1";
        mysql_query($sq l) or trigger_error(m ysql_error(), U_USER_ERROR);
        ?>
        <form action="page4.p hp" method="post">
        <input type="hidden" name="row_id" value="<?php echo $row_id; ?>" />
        <input type="text" name="third_inf o" />
        <input type="submit" />
        </form>
        [/code]

        etc...

        Comment

        • arty
          New Member
          • Nov 2008
          • 35

          #5
          thanks , i have just made something with session,i will check your version.
          thanks again.
          Last edited by arty; Nov 17 '09, 09:13 PM. Reason: edit : very interesting code

          Comment

          Working...