469,341 Members | 7,697 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,341 developers. It's quick & easy.

PHP mysql survey

35
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?
Nov 16 '09 #1
4 3245
Atli
5,058 Expert 4TB
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.
Nov 16 '09 #2
arty
35
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
Nov 16 '09 #3
Atli
5,058 Expert 4TB
What do you mean?

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

page1.php
Expand|Select|Wrap|Line Numbers
  1. <form action="page2.php" method="post">
  2.     <input type="text" name="first_info" />
  3.     <input type="submit" />
  4. </form>
  5.  
page2.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // Get the data from the last form
  3. $first_info = mysql_real_escape_string($_POST['first_info']);
  4.  
  5. // Insert a new row into the database
  6. $sql = "INSERT INTO tbl(first_info) VALUES('{$first_info}')";
  7. mysql_query($sql) or trigger_error(mysql_error(), U_USER_ERROR);
  8.  
  9. // Get the ID of the row that was just created.
  10. $row_id = mysql_insert_id();
  11. ?>
  12. <form action="page3.php" method="post">
  13.     <input type="hidden" name="row_id" value="<?php echo $row_id; ?>" />
  14.     <input type="text" name="second_info" />
  15.     <input type="submit" />
  16. </form>
  17.  
page3.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // Get the data from the last form
  3. $second_info = mysql_real_escape_string($_POST['second_info']);
  4. $row_id = mysql_real_escape_string($_POST['row_id'])
  5.  
  6. // Update the row in the database with the new info
  7. $sql = "UPDATE tbl 
  8.         SET second_info='{$second_info}' 
  9.         WHERE row_id={$row_id}
  10.         LIMIT 1";
  11. mysql_query($sql) or trigger_error(mysql_error(), U_USER_ERROR);
  12. ?>
  13. <form action="page4.php" method="post">
  14.     <input type="hidden" name="row_id" value="<?php echo $row_id; ?>" />
  15.     <input type="text" name="third_info" />
  16.     <input type="submit" />
  17. </form>
  18.  
etc...
Nov 17 '09 #4
arty
35
thanks , i have just made something with session,i will check your version.
thanks again.
Nov 17 '09 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by GTF | last post: by
2 posts views Thread by Jon Dellaria | last post: by
4 posts views Thread by Mmm_moo_cows | last post: by
175 posts views Thread by Sai Hertz And Control Systems | last post: by
3 posts views Thread by Miyagi | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by haryvincent176 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.