Page 1 of 1

Using php to echo result or using Javasript pop up menu

Posted: Tue Aug 01, 2006 3:26 am
by mohson
Do you feel that it is better to echo results of your actions like below:

Code: Select all

//* This echo works because if the db selection porked, the die would have been called //*
echo '<h1>Database Selected</h1>';
Other examples would be 'record added ' record updated' 'record deleted'

Through PHP as opposed to javasript as javasript only produces a pop up box pertaining to the user clicking 'submit' button.

But the PHP METHOD is more 'real' as it checks if insert/update/delete actually happened

Would do you guys think?

Posted: Tue Aug 01, 2006 7:06 am
by feyd
I have no idea what you're asking.

Posted: Tue Aug 01, 2006 7:19 am
by mohson
OK.

In some of my pages I have returned a message stating that record has been added this has been echo'ed as a message as opposed to using javacript.

What im asking is: isnt it better to echo the returned message as the PHP code checks to see if the insert is ok and then resturns a message as oppossed to java which just produces a pop up item when you click submit whether or not the record has succesfully been added.

So for example when using if else statements, i.e. php to produce an echo statement stating the record has been added the criteria is that 'Yes' this record now exists on the table.

But with javascript the return pop up item the criteria is simply 'Yes' the suer pressed the submit button.

Is there any truth to this argument.

Have I explained myself a bit better this time?

Posted: Tue Aug 01, 2006 7:25 am
by GM
I assume you want to inform your users of that an action has been completed correctly - ie: "Record Added".

I use a page called "message.php" which I redirect to after completing an action. The page "message.php" takes a URL parameter which identifies which message to display (pulled from database), any parameters to be included in the message, and where to redirect the user to afterwards - a typical URL would look like:

/message.php?id=RECORD_ADDED&parameters=appointment;20-08-2006&return_to=home.php

This might output something like:

A new appointment has been created for the 20-08-2006. Click <a href="home.php">here</a> to go back
mohson wrote: javasript only produces a pop up box pertaining to the user clicking 'submit' button.
Not true - javascript alerts can be echoed to the screen by PHP at any point in the script's execution.

Posted: Tue Aug 01, 2006 7:28 am
by mohson
Ok so If was looking for a reason to use the echoed statement - simply printing out in text then I could argue that javascript will not work on everyones machine soo its better to use my method?

Is this a valid point?

Posted: Tue Aug 01, 2006 7:29 am
by feyd
It's better and more accessible if the message is in the page.

Posted: Tue Aug 01, 2006 7:33 am
by GM
mohson wrote: Ok so If was looking for a reason to use the echoed statement - simply printing out in text then I could argue that javascript will not work on everyones machine soo its better to use my method?

Is this a valid point?
Yes.

In general, Javascript alerts are used mostly to advise the user of some problem with data they've inputted, and is used as a first level of validation/sanity check of data. It is used to let the user know that there is some problem ie: "You haven't entered a username!", "Date of Birth must be in format dd/mm/yyyy" etc.

Status messages such as "Record Added" or "Record Deleted" would usually be echoed to the screen in some manner.