News Register Control Panel Private Messages Members List Team Search News Posts About Us

Linux Advisory » Q & A - Discussions » Programming & Coding » Variable from another variables value PHP » Hello Guest [login|register]
Last Post | First Unread Post Print Page | Recommend to Friend | Add Thread to Favorites
Post New Thread Post Reply
Author
Post « Previous Thread | Next Thread »
Telos Telos is a Male
Super Moderator


Registration Date: 06-04-2003
Posts: 130
Location: Finland
Linux Distro: hmm....

Rating:
3 Votes - Average Rating: 7.00

Level: 19 [?]
Experience Points: 18.487
Next Level: 22.851
4.364 point(s) of experience needed for next level

OFFLINE

Variable from another variables value PHP Post Reply with Quote Edit/Delete Post Report Post to a Moderator       IP Information

ok, I have this tricky problem. Here's my situation:

I have a form which html code I get from a db. I mean the html code of the answer fields like the inputs and textareas and so on.

Then I should process the form when it's submitted. I have also the answer fields's name field names stored in the db where I get them so I know what is the name of every field that comes to my process page.

The problem is that how can I insert them into db because I need a variable which is the same name as the other variables value. Here's an example:

I get the name field name from db:
code:
$sql3 = mysql_query("SELECT * FROM ir_vastaustyyppi WHERE tyyppi = $vastaustapa ORDER BY vaihtoehto ASC");
while($result = mysql_fetch_array($sql3))
{
$nimi_kentta = $result['nimi_kentta'];
// Here I do the insert mysql_query
}


ok now I have the name fields name stored inside that $nimi_kentta variable. But let's assume the value is "name" so in that case I need a variable $name so I can insert them to db. So how do I create a variable name on the fly according to what values the $nimi_kentta gets ? Save me!



07-23-2003 10:32 Send an Email to Telos Homepage of Telos Search for Posts by Telos Add Telos to your Buddy List Add Telos to your Contact List AIM Screenname: dreamimpactcom
Telos Telos is a Male
Super Moderator


Registration Date: 06-04-2003
Posts: 130
Location: Finland
Linux Distro: hmm....

Rating:
3 Votes - Average Rating: 7.00

Level: 19 [?]
Experience Points: 18.487
Next Level: 22.851
4.364 point(s) of experience needed for next level

OFFLINE

Post Reply with Quote Edit/Delete Post Report Post to a Moderator       IP Information

I solved the problem. Was actually quite easy. After I got the name of the name field I just recieved the variable like this:
code:
$name = $_POST[$nimi_kentta];

and then I could add it to database using the $name variable. Quite funny that it took 5 and half hours for me to get it right Smile



07-23-2003 16:02 Send an Email to Telos Homepage of Telos Search for Posts by Telos Add Telos to your Buddy List Add Telos to your Contact List AIM Screenname: dreamimpactcom
Ravish Ravish is a Male
Administrator




Registration Date: 12-27-2002
Posts: 703
Location: Internet
Linux Distro: Redhat, Mandrake, Gentoo

Rating:
15 Votes - Average Rating: 8.13

Level: 29 [?]
Experience Points: 211.828
Next Level: 242.754
30.926 point(s) of experience needed for next level

OFFLINE

Post Reply with Quote Edit/Delete Post Report Post to a Moderator       IP Information

quote:
Originally posted by Telos
Quite funny that it took 5 and half hours for me to get it right Smile

Really? Here is another thing you could try:
just put this somewhere at the top of the script
code:
extract($_POST);

This will create the variables automatically from arrays. Like it will create a variable called $nimi_kentta with the supplied value by form.



07-23-2003 16:34 Send an Email to Ravish Homepage of Ravish Search for Posts by Ravish Add Ravish to your Buddy List AIM Screenname: Ravi5h YIM Screenname: ravishahuja1
Telos Telos is a Male
Super Moderator


Registration Date: 06-04-2003
Posts: 130
Location: Finland
Linux Distro: hmm....

Rating:
3 Votes - Average Rating: 7.00

Level: 19 [?]
Experience Points: 18.487
Next Level: 22.851
4.364 point(s) of experience needed for next level

OFFLINE

Post Reply with Quote Edit/Delete Post Report Post to a Moderator       IP Information

yes, but the thing is that with PHP you can use POST variables without any action at all but you had to do it like that to make it work. But the satisfaction was great when I finally solved it Smile



07-23-2003 17:52 Send an Email to Telos Homepage of Telos Search for Posts by Telos Add Telos to your Buddy List Add Telos to your Contact List AIM Screenname: dreamimpactcom
Post Reply:
Title (Optional):
Message:


Convert URLs: Automatically converts internet addresses into links by adding [url] and [/url] around them.
Email Notification: Notifies you by email every time there is a new post in this thread.
Deactivate smilies in this post.
Add Signature: Displays your signature in this post.


Tree Structure | Board Structure
Post New Thread Post Reply
Go to:


Powered by Burning Board 2.0.2 © 2001-2002 WoltLab GbR
English Translation by Satelk