Page 1 of 1

Is there a more elegant way to do this?

Posted: Thu Jan 16, 2003 7:30 am
by jonat8
Hi :)

I have a simple guestbook script that I've written that works from mySQL. When a user follows a link to the guestbook (gbook.php) it displays an "Add a New Entry" section which is a form and in the code below that is the request to mySQL for all the entries so the user can read previous entries. The 2 sections (add new entry and view previous entries) are all on one script, i.e. no includes. The form is just before the <?php section starts.

But my problem is this...
When a user adds a new entry, my form submits the form entries to another php script (gbookadd.php) that opens in a new window. That script makes the addition and tells the user to close the newly opened window and refresh the previous one to see their new entry.

This isn't very elegant, is there a more elegant way to do this that doesn't require either a)a new window opening or b)the user having to refresh the previous page to see their submission.

This is written for integration into a PHP-nuke site so I'm a bit wary of using includes because to load the site properly you have to use http://your-site-address/folder/modules.php?name=G-book or whatever.

Thanks in advance for any help :)

Posted: Thu Jan 16, 2003 9:03 am
by laserlight
Well, you could use the same page to "do the addition".
In that case, you might be better off making gbookadd.php an include file containing say, the function that updates the database.

Then you just use this function in gbook.php when the form is submitted.
If you extract from the database for the listing after calling the function on the form submission, the update should be displayed to the user.

Posted: Thu Jan 16, 2003 10:06 am
by jonat8
Thanks very much :D
Worked perfectly, just put an include to my gbookadd.php file in my main gbook.php file and redirected the form submission to modules.php?name=G-Book for PHP-nuke to display all its blocks and it worked fine.