[SOLVED] Storing variable names in a MySQL DB

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

[SOLVED] Storing variable names in a MySQL DB

Post by impulse() »

Hello.

At the minute I'm storing a line similar to:

"Dear $title $fName[0] $sName, Can you confirm your email address is $email".

And then I have in a PHP page dropdown box where the value of an option is equal to the above line. I then have some Javascript which echo's out the value of the dropdown selection. The variables, $title, $fName & $sName already exist in the code, so I want it to print the contents of those 3 variables but it's not. It's printing the variable names.


How would it be possible for a loop that creates a dropdown list to echo the contents of a variable in the dropdown value?
Last edited by impulse() on Fri Feb 23, 2007 6:26 am, edited 1 time in total.
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post by impulse() »

So far I have tried to use eval but it's not returning any data. Here is my code so far:

Code: Select all

$title = $_POST["title"];
  $fName = $_POST["fName"];
  $sName = $_POST["sName"];
  $email = $_POST["email"];
  $notes = $_POST["notes"];

while ($res = mysql_fetch_array($query)) {

    $template[$i] = $res['template'];
    $i++;

  }
<select name = 'OperationDropDown' onChange = 'fillText()'>
    <option value = '' selected = 'true'> Select an operation </option>
    <?php
    for ($i = 0; $i < count($template); $i++) {
      echo "<option value = '";
      eval($template[$i]);
      "'> Template $i </option>";
    }
    echo "<option value = '$templateTest'> Template Test </option>";
    ?>
    </select> <br><br>
There are 2 templates in the DB at the moment, they look like this:

1. "echo "fName sName";"
2. "echo "{$fName} {$sName}";
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post by impulse() »

I just eval'd the whole line, rather than part:

Code: Select all

for ($i = 0; $i < count($template); $i++) {
      eval($template[$i]);
    }
And template[$i] would equal:

Code: Select all

echo "<option value = '$fName'> $i </option>";
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

8O

You go impulse -- you're a one man problem-having-and-solving machine!

Now if only you could somehow moderate yourself as well...
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post by impulse() »

You ask far too much.

Would you prefer I use 'Edit' over 'New Reply' in this case?

Sometimes I just get so excited the rules don't seem to apply to me :)
Post Reply