[pmwiki-users] Fwd: Re: Interacting with MySQL

Rick Cook rick at rickcook.name
Tue Jan 15 01:03:43 CST 2008

Forgot to switch to the mailing list as the addressee.

----------  Forwarded Message  ----------

Subject: Re: Interacting with MySQL
Date: Tuesday 15 January 2008
From: Rick Cook <rick at rickcook.name>
To: Ben Stallings <ben at interdependentweb.com>

On Monday 14 January 2008 20:34:02 you wrote:
> Rick Cook wrote,
> > I am attempting to connect a PmWiki form (or forms) to a MySQL database.
> > I was able to quickly get UpdateForm to allow me to enter new records
> > into the database including enforcing some "Required" fields and having
> > one field that is required to be unique across all rows. I could also
> > update an existing record if I included a "where=UniqueField" clause in
> > the "(:update form...:)". In that mode, I could not create new entries in
> > the database.
> >
> > With those two results, I thought "Okay, I just have the unique field
> > entered in a simple form, use SelectQuery to see if that value exists in
> > the database and put up a populated UpdateForm for existing entries or an
> > unpopulated UpdateFrom (except for the unique field). After several hours
> > attempting to get the data from the simple input form using $_POST, I was
> > successfully able to get the SelectQuery populated by creating a custom
> > PageVariable and populating it from the POST data.
> >
> > Now I am stuck. I have the successful SelectQuery results and can see the
> > record if I don't use "display=custom". I can't seem to grab any of the
> > data from the query to use in any decision process or to populate the
> > form - the {`fieldname`} syntax does not seem to be working (or maybe I
> > don't know how to make it work).
> Rick, it sounds like you're trying to use UpdateForm with a table whose
> primary key field is not an auto-incrementing integer.  UpdateForm is

Actually, the table does have an auto-incrementing integer key field. It also 
has another field that I am requiring to be a unique email address for each 
row of the table. I am actually trying to use the SelectQuery to pick out the 
appropriate integer key field if there is a record that already has the email 
address entered on the beginning page.

> designed to be used with tables that have integer, auto-increment key
> fields.  The only way that it knows it's supposed to create a new record
> is if the key value is *not specified* -- in that case, a new record is
> created with the next key value.  If the key value is specified -- even
> if that key value doesn't yet exist in the table -- UpdateForm attempts
> to use an update rather than an insert statement.

Any suggestions about how to "not specify" the key value for the case when the 
key value doesn't exist and also specify it when it does? The (`ContactID`)

> (The good news is, you only need one form, not two like you're
> describing.  If you use it correctly, the same form will handle both
> inserts and updates.)

Some more stumbling through various configurations of the page was already 
leading me toward that conclusion.

> If I'm right, you have a couple of choices:
> 1) change your table so that it has an auto-increment key field

Already done. As indicated above, I'm having problems getting the key field 
specified (or not) out of the results of the SelectQuery.

> 2) use DataQuery instead of SelectQuery and UpdateForm

If I could figure out how to make DataQuery provide the desired functionality, 
DataQuery would be fine with me.

> 3) change your copy of UpdateForm so that it can handle other kinds of
> key fields, and then contribute it back to the recipe page when you've
> got it working

I wasn't attempting to do something new. Well, at least I didn't think I was. 
I was simply trying to do something to figure out whether the requested email 
address already existed in the database.

> I regret that I am not available at this time to do more development on
> UpdateForm myself, but I'm happy to answer other questions you may have.
>   Sorry the documentation was unclear -- I'll fix it now!  --Ben S.

I understand not having time. The functionality I am trying to add is just one 
example out of many of my own version of "volunteeritis".

Thanks for any pointers you can provide.



More information about the pmwiki-users mailing list