Jump to content

Best Way To Save A Form In Sql Database?


rmpotter
 Share

Recommended Posts

You could quickly WHILE through the form inputs, sanitizing them and adding them to an associative array, then implode the array into a string to store in a database, so you've only made one db call, and then when you want the values again, read the one field with all the data and explode it into an array. You could have the value attribute of the input fields set to something like <?php echo ($_SESSION["fieldname"]?$_SESSION["fieldname"]:""); ?> and when you're reading the values again, set them to the session variable. But only good for temporary storage, as it compiles all your data into one field.

Link to comment
Share on other sites

It's probably better to use serialize and unserialize instead of implode and explode, serialize is specifically for creating a string representation of a structure like an array. You could serialize all of $_POST, for example, and store that in the session.

Link to comment
Share on other sites

It's probably better to use serialize and unserialize instead of implode and explode, serialize is specifically for creating a string representation of a structure like an array. You could serialize all of $_POST, for example, and store that in the session.
This is what I have done in the past and it works awseome for simple forms. This form is very complex and reloading all the values would be time consuming to program and prone to error... Is it possible to take a PHP array and load it into a java array? I would hope that by doing so I could run through each variable by name and repopulate it once the form has loaded again.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...