Welcome Guest, Not a member yet? Register   Sign In
A bit stuck...
#1

[eluser]incog03[/eluser]
I've created a form, that once you submit will enter it into the database. After this happens the user will then be directed to a preview page where they can view the answers they've put in the form. Then they will agree to it being displayed.

I'm wondering how to populate the preview form with the correct row of the database if the primary key is auto-increment. Because until the database initially creates a row there will be no primary key for me to use to pull the data back out and display it.

Any ideas how to resolve this? Or a better a idea..a
#2

[eluser]JHackamack[/eluser]
If I am reading your problem right then the following might work:
1. Show form
2. Insert data into DB Giving you a primary key
3. Preview data
4. Agree to publish data by updating the DB row with an enabled flag

The way this works is there is an additional table column called enabled that is defaulted to 0. When you agree to display the form it's changed to 1. Displaying data to the public only looked for the enabled field where the value is one.
#3

[eluser]incog03[/eluser]
I get what you mean by the flag and that's something I will definitely implement, but how does the preview screen know what row of the database to call? Because with the additional flag row there could be many people adding new rows at that particular time
#4

[eluser]JHackamack[/eluser]
When you process the for form and insert into the DB you can get back the inserted I'd with: $this->DB->insert_id(); then you can use that to grab the DB row or redirect to a dedicated preview function.
#5

[eluser]incog03[/eluser]
Excellent! I had no idea there was a way to handle this, thank for your time, much appreciated.




Theme © iAndrew 2016 - Forum software by © MyBB