error passing

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Ree
Forum Regular
Posts: 592
Joined: Fri Jun 10, 2005 1:43 am
Location: LT

error passing

Post by Ree »

on my current admin interface, when a user adds a new db record (via form), the POST of the form goes to a certain php file where entered data is processed. after that i forward the user to another page (let's say page.php)(i use header) on which i want to be able to display a message (something like 'Data entered successfully' or error message). i know i could just pass a message variable via query string, check it on page.php and display the appropriate message, but i don't want it possible to enter something similar to //domain/admin/page.php?error=added_ok in the browser and see the page.php with corresponding error message. what would be your suggestions to solve the problem?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

use http://www.php.net/session... (Other alternatives: cookies, database, files but notice that session can be used as a wrapper for those alternatives)
User avatar
harrisonad
Forum Contributor
Posts: 288
Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:

Post by harrisonad »

I offer a simpler solution than what master timvw intelligently suggested.

Request Strings:

Code: Select all

admin/page.php?msgtype=success
admin/page.php?msgtype=error
admin/page.php
Page.php

Code: Select all

$msgtype = (isset($_GET['msgtype'])?$_GET['msgtype']:'success'); // provide default value
if($msgtype=='success'){
    $msg = 'Transaction completed successfully!';
}elseif($msgtype=='error'){
    $msg = 'An error occured while processing the transaction';
}
echo $msg;
Ree
Forum Regular
Posts: 592
Joined: Fri Jun 10, 2005 1:43 am
Location: LT

Post by Ree »

thank you, harrisonad, but i already know your suggested way, and if you read my post more carefully, you would have noticed that. :wink:
Post Reply