Solved

using same form for add and edit in php

Posted on 2014-11-07
3
207 Views
Last Modified: 2014-11-17
Hi

I usually use the same form in php for add and edit. If the form is for add i leave the fields empty and change the button text to add. If the page if for edit i populate it with appropriate values from the database and change button text to update. There may be some other minor tweaks too. However I have been reading around and saw this

"http://stackoverflow.com/questions/6657331/add-view-edit-mysql-entries-with-the-same-php-form"

"It's generally quite easy to use the same form. Another question is how you solve validation errors and not making the user re-fill the form - this gets solved as in the same process. You'll need some helpers for the select fields and any checkbox/radio fields. Exactly how much the helpers do is up to you, but these will get you started:"

I dont know what this means. Why do i need helped? If the user changed a select or radio button on an edit then the form validation would pick it up wouldnt it if there was a problem

If there is a simple design pattern for using the same form for adds/updates I would be grateful if you could point me to it

thanks
0
Comment
Question by:andieje
3 Comments
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 250 total points
ID: 40429664
I often do it the way you do.  I would ignore that page from Stackoverflow, there is a lot missing from their code examples.
0
 
LVL 48

Expert Comment

by:PortletPaul
ID: 40429689
You also need to consider the quality measures of that page
it is 3 years old
There is no accepted answer
there are only 2 responses
there is only one upvote (in 3 years)

not all web pages are of a high quality :(
0
 
LVL 109

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
ID: 40429825
HTML Form processing is discussed here:
http://php.net/manual/en/tutorial.forms.php

There is no single, simple way to handle text inputs, radio buttons and check boxes.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_5450-Common-Sense-Examples-Using-Checkboxes-with-HTML-JavaScript-and-PHP.html

Table maintenance is a fairly advanced concept in PHP and MySQL.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_12335-PHP-and-MySQLi-Table-Maintenance.html

A sensible design pattern using MySQL might take advantage of the MySQL-only REPLACE INTO statement.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PHP strings vs array errors 13 32
How to call a web service and get the results posted in a form in PHP 9 49
php help 34 58
jQuery force form POST 7 42
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question