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?
PHP mysql survey
Collapse
X
-
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
Comment