473,324 Members | 2,268 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

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 3473
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

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

Similar topics

2
by: Paris_Sucks | last post by:
I'm trying to redirect when testing for certain condidtions as shown below. When the conditions are ture, it redirects, but still goes ahead and processes the sql query. What am I doing wrong??? ...
1
by: GTF | last post by:
PHP Web Survey Idea.. I have been given an opportunity to create a web based survey. This is a fairly lengthy survey of 60 pages on paper (various multiple choice and free form). These are...
2
by: Jon Dellaria | last post by:
I have been using MySql as the database using JSP's and JavaBeans but recently I have wanted to start using the database connection pooling mechanism built into TomCat. I think I am having a...
4
by: Mmm_moo_cows | last post by:
Hi, I'm new to the world of mysql and i'm having alot of trouble with it. All i want to do is create a page with a response form, e.g. name etc and some radio buttons (part of a uni project,...
175
by: Sai Hertz And Control Systems | last post by:
Dear all, Their was a huge rore about MySQL recently for something in java functions now theirs one more http://www.mysql.com/doc/en/News-5.0.x.html Does this concern anyone. What I...
110
by: alf | last post by:
Hi, is it possible that due to OS crash or mysql itself crash or some e.g. SCSI failure to lose all the data stored in the table (let's say million of 1KB rows). In other words what is the worst...
3
by: Miyagi | last post by:
I am running a custom setup that the workgroup here needs to run. IIS6 with Windows Server 2K3. PHP install was a little tricky but only required the Environment Path to include C:\PHP\ and use the...
1
by: runsun | last post by:
I am new in PHP/Mysql. I want to input sth from website to mysql, then output the formatted data to .txt, and finally use Excel to open the .txt file. I believe there are better and simpler ways than...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.