I am new to php but have some scenarios in which I want to use it. Since I am new I know I need to do a lot of studying but for now, before I delve into it too much just to find out something isn't possible, I would like to know if something like this is possible. You don't need to spend a lot of time giving me all the code but if I could get some ideas or where and how to search for what I need would be great.

I found a good thread that explained half my question but I want to add to it. I want to be able to search for a specific record (only one at a time) and if it is available, then edit it but if it is not available then I want to insert it. For example, I work with Work Order numbers. If a certain WO is already in the database I want to edit it, but if the WO isn't found, I want to insert a new record using the number I used to search. I'm thinking I would somehow input my WO number into a variable and then first check to see if it is in the database. If it does exist I would populate my form with that record and edit what I need. If it didn't exist I would go to a different part of code somehow and use that variable to populate the form for a NEW record and finish entering what I need and then insert the new record. Or is there a shortcut to all this that it would automatically know to insert if it doesn't already exist? I do not want to be able to insert the same WO number more than once.

I've worked with local databases before and I think this would be possible but would like some input. Like I said, you don't need to supply me with the whole code, but maybe if I could get some php commands that would be necessary so I can study up on them.

Thank you

7 Years
Discussion Span
Last Post by jkon

Yes this is possible.

A simnple solution would be:

If resultsdet of query = 0, create form with a field with the WO number (a locked textbox or a hidden field), else enter the data into a form.

Edited by diafol: n/a


There could be many ways to it, and I will share with you one of the simplest. As I understood you have three steps. Lets say that the table has only tree fields ID,WORK_ORDER and NAME. The first step is a simple form with a text input lets call it workOrder where the user enters the WORK_ORDER to search and posts it to the second page.

The second page first declare empty variables $id , $workOrder , $name ($id = "") . If isset $_POST["workOrder"] then we will search for it. Make a select and if you have any results put them in $id,$workOrder and $name. Than create a form that submits to the third page. Put the id in a hidden field with value $id , workOrder in a text field with value $workOrder (before closing the input tag you could add a check that if $workOrder isn’t "" then add readonly='readonly' to lock it) and a text field for name with value $name.

So in the third page you know if you should insert or update . If $_POST["id"] isn’t "" then you will update using that ID else you will insert.

Of course you could do all that in two steps and even in one. But I explained a really simple solution and of course there are many thing out there for security and generally what you want to do.

This topic has been dead for over six months. 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.