Solved

passing variable from page to page dynamically

Posted on 2006-06-22
6
238 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
deprecated mysql extensions 1 51
JSON decode 5 42
PHP substring 3 46
PHP and accessing Array Elements 3 29
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

738 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