Page 1 of 1

[SOLVED] Storing variable names in a MySQL DB

Posted: Fri Feb 23, 2007 5:38 am
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?

Posted: Fri Feb 23, 2007 6:14 am
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}";

Posted: Fri Feb 23, 2007 6:27 am
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>";

Posted: Fri Feb 23, 2007 7:11 am
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...

Posted: Fri Feb 23, 2007 7:28 am
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 :)