0

Hi,

What code would i need to use for my php form, so when my record is saved using my save button on my form to my mysql database, it displays a message to say "Record Saved".

2
Contributors
11
Replies
12
Views
5 Years
Discussion Span
Last Post by morrisproject
0

mysql_query() returns TRUE on success or FALSE on error for INSERT and UPDATE queries. So just using simple if else you can display what message you want to show.

$result = mysql_query($InsertOrUpdatequery);
if($result)
{
     echo "Record Saved";
}
else
{
     echo "Failed to save the Record";
}
0

ok thanks.

does $result need to be defined anywhere for this to work, because just inserting this code doesnt display any message?

0

Yes i am. I have inserted the code within my BODY tag but it doesnt display any messgae when a record is saved.

0

Ahh.. :) :) You have to put it in the file which is called when form gets submitted, i.e the file given as the action of the form

0

i have got a file in form action, i use the save button to save the records which redirects to layout page if the record is saved. if i put the code in the history still no message box displays.

0

i haven't got a file in form action, i use the save button to save the records which redirects to layout page if the record is saved. if i put the code in the history still no message box displays.

0

I did not get what you meant by "if i put the code in the history still no message box displays."

Actually what should be done is,
-> If your action file is the same as form containing file, you have to do message displaying in the same file
-> If your action file is a separate file and after completing the database accessing it not redirecting to some other view you have to display the message in the action file.
-> If your action file is a separate file and after completing the database accessing it is redirecting to some other view, you have to pass a GET parameter to identify the status(Succeeded or Not) of the database action.

0

actually ignore that i am going to change what i want to do on the save button.

My layout.php form has many buttons it and a current date field, which all have a unique id/name. when the button is clicked it uses the id and date on the new.php, so when the record is saved it is saved relating to the id and date and other fields are filled in.
the save button takes the user back to layout.php and i want the button to change colour when the record is saved, it would need to use both button id and date because the user might not get all data entered in one day, therfore would have to go back to a particular date to see which buttons where done, as they would display a different colour.

how can i do this?

0

As I understood your layout.php gets populated from the saved data, right? So when you are repopulating just after saving, I think you can perform a conditional check to see which data has been already entered and change the color of the relevant button by adding a css class to that button. Hope I understood your explanation correctly.

0

yes thats correct, but im not sure what the code would be to check which data is saved on that particular date and using the button id, to identify which button needs to change colour.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.