Solved

passing variable from page to page dynamically

Posted on 2006-06-22
6
233 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
check mysql insert 12 41
Generate PDF from MySQL using PHP 3 53
$_GET call between URL 3 41
Find RGB colors from a screen. 2 17
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

749 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