generate $_SESSION variables from database
Posted: Thu May 31, 2007 10:00 pm
What I have is a small table in a database with a couple columns including "name", "label", and "used". My goal is to make a generic "contact" page for my clients and modify just the database to display and use the fields they want.
The only problem I'm having with this is creating some of the session variables I need.
so for instance, theoretically I should be getting
but its not even saying the variables are set, let alone that they have a value.
Other session variables I set manually work though, like:
I don't get whats going on. Anyone have any ideas?
The only problem I'm having with this is creating some of the session variables I need.
Code: Select all
$query_used = "SELECT * FROM `form` WHERE `used`=1";
$result_used = mysql_query( $query_used ) or die ("could not query the database: <br />". mysql_error());
while ($row = mysql_fetch_assoc( $result_used )){
$name = $row['name'];
// name corresponds to: <input name="first" ...
$_SESSION[$name] = htmlentities($_POST[$name]);
}Code: Select all
$_SESSION['first'] = "bob";
$_SESSION['last'] = "anderson";
$_SESSION['email'] = "bob@domain.ext";
// etc as it hands out the results of the query
// keep in mind the results of the query will exactly match that of the $_POST data, as the fields are generated in the same manner.Other session variables I set manually work though, like:
Code: Select all
$ip = getenv("REMOTE_ADDR");
$_SESSION['ip'] = $ip;
// or
$_SESSION['msg'] = htmlentities($_POST['msg']);
// these are set manually (no loop).