Forums

This topic is locked

Success Message in alternative pages

Posted 15 Apr 2005 04:59:53
1
has voted
15 Apr 2005 04:59:53 Sidney Rippetoe posted:
I was wandering if anyone knew how to have a "Success Message" show up on a page that isn't designed for the success message.
LOike most people will make the success.php, but instead I am needing the success message to just show up like in the Amdin page just after an action like editing or adding content to a db?
Can someone popint me in the right direction or explain to me in easy talk of how this can be done?
Thanks in advance.

Replies

Replied 15 Apr 2005 12:15:17
15 Apr 2005 12:15:17 Matt Bailey replied:
Essentially you would set up a function to do whatever it is you want to do and in that function you would define the error message. Then when your function is run it checks the conditions that have been set and acts accordingly, displaying the error message if neccessary, or performing some other task, like redirecting the page as in the example below (it uses PHP, but you could do it in any number of other coding languages I guess).

THIS GOES BEFORE ALL THE HTML STUFF

<pre id=code><font face=courier size=2 id=code>if($HTTP_POST_VARS['action']=="login"{
if($totalRows_rsLogin==0){
$errorMessage = "&lt;br /&gt;Your username and/or password has not been recognised";
mysql_free_result($rsLogin);
} else {
mysql_free_result($rsLogin);
session_register("Administrator";
$HTTP_SESSION_VARS['Administrator'] = $HTTP_POST_VARS['Username'];
header("Location: /admin/home.php";
}
}</font id=code></pre id=code>

THIS GOES ON YOUR PAGE WHERE YOU WANT THE ERROR MESSAGE TO APPEAR

<pre id=code><font face=courier size=2 id=code>echo "$errorMessage";</font id=code></pre id=code>

Obviously you can't just copy and paste this into your document, but it outlines the principles and may help get you started.

___________________________________
* Sorry... how do you do that again?... *
Replied 21 Apr 2005 02:34:08
21 Apr 2005 02:34:08 Sidney Rippetoe replied:
I think I am doing something wrong, I can't seem to get the result I am looking for.
Although I can read what the code you wrote is doing, I just am not very confident in writing code.
Can you give me some noob help with this?
Thanks.
Replied 21 Apr 2005 12:15:22
21 Apr 2005 12:15:22 Matt Bailey replied:
Ok. Here's a much simplified version (this is the whole of the code):

<pre id=code><font face=courier size=2 id=code>&lt;?php
if($HTTP_POST_VARS['action'] == "showmessage" {
$MyMessage = "This is my message";
}
?&gt;
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"www.w3.org/TR/html4/loose.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;title&gt;Show Message&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;form action="" method="post" name="ShowMessage" id="ShowMessage"&gt;
&lt;input name="ShowMessage" type="submit" id="ShowMessage" value="ShowMessage"&gt;
&lt;input name="action" type="hidden" id="action" value="showmessage"&gt;
&lt;/form&gt;
&lt;p&gt;&lt;?php echo "$MyMessage"; ?&gt;&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</font id=code></pre id=code>

Try it out and you'll see how it works. Let me know if you're not sure of anything.

___________________________________
* Sorry... how do you do that again?... *

Reply to this topic