Jump to content

Designing multiple php pages


yoda69

Recommended Posts

Hey,

 

I'm designing an online psychological experiment that use several php pages. In every page there is another question or questionnaire. ALL the data generated in these pages go to the same mysql table. My design right now update the same row for different fields (for the same user) in every single page of the experiment.

 

I was thinking that it probably consumes a lot of time and traffic to access the database in every page and update the same row for the different fields. Can anyone suggest a better way of doing so?

 

Is there a method to store all the data in a temp location and then update it once to the database?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/198357-designing-multiple-php-pages/
Share on other sites

How are you distinguishing between users? If you're using unique IDs then all you need to do it:

$query = "UPDATE `*questions_table*` SET `*question1*` = '*answer1* WHERE `user` = $id";

Obviously change the asterisked values to your table name, question field and answer variable respectively.

 

edit If I'd read your questions correctly, then I'd get the gist of what you wanted. It's not that much traffic really. But if you did want to do it, use sessions.

 

//top of page
session_start();

// Place each answer to the question into a session:
$_SESSION['question1'] = $answer1;

// Do this on all 3 pages, then after question 3, take the form to a page that updates all 3 fields in your database with the session values.

Thanks for the answer.

I think I will rather use sessions.

 

However, what I still don't get is how to pass the variable data from the form into a variable in the same page.

 

for example here is my code:

<?php session_start();?>
<html>
<head>
</head>

<body>
<div id="container">

  <form id="form1" method="post" action="">
    <label>Fill this Data
    <input type="text" name="1" id="1" />
    </label>
    <p>
      <label>
      <input type="submit" name="2" id="2" value="Submit" />
      </label>
    </p>
  </form>
  
  <?php
  $_SESSION['question1'] = $answer1;
   ?>
</div>
</body>
</html>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.