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".

Recommended Answers

All 11 Replies

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";
}

ok thanks.

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

$result is the return value of mysql_query(). You are using mysql with php right?

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

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

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.

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.

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.

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?

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.