Solved

passing variable from page to page dynamically

Posted on 2006-06-22
6
228 Views
Last Modified: 2006-11-18
Hi,
  I want to create a form dynamically and now I can successfully create the textbox inside Form A with name=Q1, Q2 ....Q50

  Now, I want to receive the vairable from Q1,Q2 ... Q50 inside Form B in order to insert into Database

for ($i=1; $i<=$count; $i++){ //'$count; will be passed from form A
$temp="Q".$i;
"$Q".$i=$_POST['$temp'];
echo "$Q".$i;
}

$sqlString ="INSERT INTO Form6 (supervisor,Q1,Q2,Q3,Q4,Q5...) values ('$supervisor','$Q1','$Q2','$Q3','$Q4','$Q5'..)";


but fail , any help?
0
Comment
Question by:gorexy
  • 3
  • 3
6 Comments
 
LVL 10

Expert Comment

by:Khanh Doan
ID: 16966689
for ($i=1; $i<=$count; $i++)
{ //$count; will be passed from form A
  $temp = "Q" . $i;
  $Q . $i = $_POST[$temp];
  echo $Q . $i;
}

Bonmat86.
0
 

Author Comment

by:gorexy
ID: 16966808
hm..ok thanks but how about the insert SQL statement?  Can we make it dynamically?
0
 
LVL 10

Expert Comment

by:Khanh Doan
ID: 16966885
if your table like this :
QID | QVALUE
the query statement will be

$query = "INSERT INTO table (ID, QVALUE) VALUES ";
for ($i=1; $i<=$count; $i++)
{ //$count; will be passed from form A
  $temp = "Q" . $i;
  $Q . $i = $_POST[$temp];
  $tmp .= "('$temp', '$Q . $i'), "
  //echo $Q . $i;
}

$query = $query . $tmp;
$query = substr($query, strlen($query)-2);

Bonmat86.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:gorexy
ID: 16966993
my table is in the format of

field -> Q1  Q2 Q3 Q4 ......

now if I use your code, the display result is:
INSERT INTO Form (Q1, Q2) VALUES('Q1', '.4'),

my expected statement is

INSERT INTO Form (Q1, Q2, Q3, Q4 ...) VALUES('1','2','2',....),
0
 
LVL 10

Accepted Solution

by:
Khanh Doan earned 20 total points
ID: 16967033
$query = "INSERT INTO table";
for ($i=1; $i<=$count; $i++)
{ //$count; will be passed from form A
  $temp = "Q" . $i;
  $value = $_POST[$temp];
  $tmp .= "'$value' , ";
  $tmp1 .= $temp. ', ';
  //echo $Q . $i;
}
$tmp1 = substr($tmp1 , strlen($tmp1) - 2); // Cut ', ' at the end.
$tmp = substr($tmp , strlen($tmp) - 2); // Cut ', ' at the end.

$query = "(" . $tmp1 . ") VALUES (" . $tmp . ")";

Bonmat86.
0
 

Author Comment

by:gorexy
ID: 16967129
i change into this

$tmp1 = substr($tmp1 , 0, -2); // Cut ', ' at the end.
$tmp = substr($tmp , 0,-2); // Cut ', ' at the end.

and it works fine now
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question