Forums

form that can do either an insert or update

jpatti 31 Oct, 2008
I have made a form in chronoforms and a database table in MySql.

One of the form fields form corresponds to a table field that is unique. As an example, let's pretend the unique field is the user's site login.

What I want to have happen is that when a user completes the form, if there is no record for that user in my table, chronoforms writes the record (which it does), but if a record already exists, then chronoforms will update the record (which it doesn't, it gives me an error).

Doing a delete first will not work because there are other fields in the table that should not be messed with, I just need to do an insert or update, as appropriate.

In short, I want to use the same form to do either an insert or update depending on which is appropriate. I know how to do this in IIS/ASP/SQL server, but I'm a Joomla newbie.

I don't understand Joomla's architecture. When I look at the auto-generated code for my form, I don't see a SQL statement at all. I could change a SQL statement, but there's not one in there! Where is the SQL actually located?

Also, I'm using chronoforms because I do NOT know php, so please speak to me as if I'm an idiot if your answer involves php coding.

Thanks for any help.
Max_admin 31 Oct, 2008
Hi jpatti,

to update a record you will need to have the unique field in your form loaded with the unique value of the row to update, example, your unique field name is XYZ, so, you should have a form field with the name XYZ and a table column with the name XYZ, now, on new insertion, your form field will be like this :

<input type="hidden" name="XYZ" value="">


the above will make Chronoforms insert a new record in the table!

however, to update a row in the table which has the XYZ with value = 879 for example, you should have this in your form :
<input type="hidden" name="XYZ" value="879">


your table MUST have a primary key which should be this unique field.

cheers
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.