473,698 Members | 2,490 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamic Multiple Input Processing

I am creating a simple "or so I thought" php/mysql survey.
There are 3 types of Surveys, with different questions. 1 for Clients,
1 for Employees, 1 for Peers.
Questions for each survey are created, editable, removable, and drag/
drop sortable.
Options to these questions are dynamic themselves.

Basically, everything works except when I try to Insert the data into
the answers table.

The one question I'm looking for is how would one process the data
based on the respective question_id's?
Sending it to another page would require an excessive amount of _POST
variables, and like i said before, there are different questions for
each survey.

or would this work? (it doesn't seem to process)
if($submit){
for($i=$start; $i<=$end; $i++){
$query[$i] = "INSERT INTO answer(ansresul t, ansdesc, idquestion,
idsurvey) VALUES('q_$i',' exp_$i','$idque stion','$survey Type')";
$result[$i]= mysql_query($qu ery[$i]);
if($result[$i]){$success++;}
}

$msg = sprintf("Succes s: %d, Questions: %d",$success,$e nd-$start);
echo($msg);
}

Any help, advice, or direction would be greatly appreciative.
- Justin Michaliga

Jul 24 '07 #1
1 2531
That will work. Instead of 'q_$i', you can use $_POST["q_$i"].

Here's an example:

<?
# survey.php
error_reporting (E_ALL);
require_once('M DB2.php');

if ($_SERVER['REQUEST_METHOD '] == 'POST') {
$items = array();
foreach ($_POST['answers'] as $id =$answer) {
$items[] = array($id, $answer);
}
$db = MDB2::singleton ('mysql://u:p@h/d');
$db->loadModule('Ex tended');
$st = $db->prepare('inser t into answer(question Ref, answer)
values (?, ?)');
$count = $db->extended->executeMultipl e($st, $items);
echo "Inserted $count answers.<br>";
}

?>

<p>Survey</p>
<form action=survey.p hp method=post>
Who?<br>
<input name="answers[1]"><br>
What?<br>
<input name="answers[2]"><br>
Where?<br>
<input name="answers[3]"><br><br>
<input type=submit>
<input type=hidden name=submit value=1>
</form>

On Jul 24, 3:01 pm, Miyagi <justin.michal. ..@gmail.comwro te:
I am creating a simple "or so I thought" php/mysql survey.
There are 3 types of Surveys, with different questions. 1 for Clients,
1 for Employees, 1 for Peers.
Questions for each survey are created, editable, removable, and drag/
drop sortable.
Options to these questions are dynamic themselves.

Basically, everything works except when I try to Insert the data into
the answers table.

The one question I'm looking for is how would one process the data
based on the respective question_id's?
Sending it to another page would require an excessive amount of _POST
variables, and like i said before, there are different questions for
each survey.

or would this work? (it doesn't seem to process)
if($submit){
for($i=$start; $i<=$end; $i++){
$query[$i] = "INSERT INTO answer(ansresul t, ansdesc, idquestion,
idsurvey) VALUES('q_$i',' exp_$i','$idque stion','$survey Type')";
$result[$i]= mysql_query($qu ery[$i]);
if($result[$i]){$success++;}

}

$msg = sprintf("Succes s: %d, Questions: %d",$success,$e nd-$start);
echo($msg);

}

Any help, advice, or direction would be greatly appreciative.
- Justin Michaliga

Jul 25 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
13216
by: jason | last post by:
How does one loop through the contents of a form complicated by dynamic construction of checkboxes which are assigned a 'model' and 'listingID' to the NAME field on the fly in this syntax: Hunter_69. Here is what the form looks like. I have the difficulty of inserting the multiple items selected by the user the first time he visits and uses the screen and then using an UPDATE when he visits later. Model | Original Price | Reduced Price...
4
2569
by: cwwilly | last post by:
Hello, Thanks for taking a look at this! Problem: I'm trying to pass multiple dynamic values between a slaveform and a masterform. The problem I'm having is on the slaveform I loop through multiple records and want two values depending on the row they select. slaveform: x=selected
0
1975
by: Pat Patterson | last post by:
I'm having serious issues with a page I'm developing. I just need some simple help, and was hoping someone might be able to help me out in here. I have a form, that consists of 3 pages of fields. I'd like to create a page in which all of this is stored as you move along as hidden variables, until the end, when the user submits. I can't figure out one thing: I have dynamic form elements (dropdowns), that I'd like to use instead of...
3
3976
by: Leo J. Hart IV | last post by:
OK, here's another question for the experts: I am building a multi-step (3 steps actually) form using a panel for each step and hiding/displaying the appropriate panel/panels depending on which step you're on. This all works fine, but I ran into some trouble when I started creating controls dynamically in my code-behind file. Each panel contains a table which is filled with various radio buttons, text fields and the such which are...
7
3386
by: serge | last post by:
How can I run a single SP by asking multiple sales question either by using the logical operator AND for all the questions; or using the logical operator OR for all the questions. So it's always either AND or OR but never mixed together. We can use Northwind database for my question, it is very similar to the structure of the problem on the database I am working on. IF(SELECT OBJECT_ID('REPORT')) IS NOT NULL DROP TABLE REPORT_SELECTION
5
14123
by: c676228 | last post by:
Hi everyone, my colleagues are thinking about have three insurance plans on one asp page: I simplify the plan as follow: text box:number of people plan1 plan2 plan3
2
7051
by: assgar | last post by:
Hi Developemnt on win2003 server. Final server will be linux Apache,Mysql and PHP is being used. I use 2 scripts(form and process). The form displays multiple dynamic rows with chechboxs, input box for units of service, description of the service and each row has its own dropdown list of unit fees that apply. Each dynamically created row will return 3 values fee1_choice, fee1_unit and fee1_money. Note The above informaton is...
1
2916
by: quill | last post by:
Hi I am making a chatroom script and it appears that the problem seems to be that my setTimeout's are conflicting. The logic is as follows: Run a login check every x seconds Run a trigger check every x seconds
1
4603
by: javediq143 | last post by:
Hi All, This is my first post in this forum. I'm developing a CMS for my latest website. This CMS is also in PhP & MySQL. I'm done with the ADD section where the Admin can INSERT new records in Database but I'm stuck in the EDIT. I'm getting 2 problems over here. Below is the description: 1)The FIRST page will list all the records from the table which Admin can EDIT with CHECKBOX for each record to select. He can select one or more than one...
0
9171
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8905
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8880
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7743
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6532
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5869
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.