Solved

passing variable from page to page dynamically

Posted on 2006-06-22
6
201 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
Comment Utility
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
Comment Utility
hm..ok thanks but how about the insert SQL statement?  Can we make it dynamically?
0
 
LVL 10

Expert Comment

by:Khanh Doan
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:gorexy
Comment Utility
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
Comment Utility
$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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
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 …

762 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now