?
Solved

passing variable from page to page dynamically

Posted on 2006-06-22
6
Medium Priority
?
245 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 80 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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo‚Ķ
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

741 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