Using php to echo result or using Javasript pop up menu

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
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Using php to echo result or using Javasript pop up menu

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I have no idea what you're asking.
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post 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?
GM
Forum Contributor
Posts: 365
Joined: Wed Apr 26, 2006 4:19 am
Location: Italy

Post 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.
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

It's better and more accessible if the message is in the page.
GM
Forum Contributor
Posts: 365
Joined: Wed Apr 26, 2006 4:19 am
Location: Italy

Post 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.
Post Reply