Author Topic: PHP Question  (Read 3110 times)

Canuck

  • Eh?!!
  • Founders
  • Posts: 792
  • Karma: +51/-3
  • Andy Moog Fan
    • My Website
PHP Question
« on: August 14, 2007, 12:56:56 AM »
Hi,

Not sure what the best way to go about this is, hoping someone could guide me in the right direction.

When a form is submitted, I perform validation with PHP, if everything is okay, I insert the data into the database.

I have another page in which I am able to edit the entries (submitted above), so I display the entires, the user clicks edit (a single entry), and it populates the original form. They make changes and submit again.

Here is the problem, if they submit again, it will create another entry, all I want to do is edit the existing entry, but all the code would pretty much be the same besides the insert/update query, since I want to perform all the validation again.

Could I use a hidden field in the form indicating update/insert, and check that before I perform the query?

Could I send the calling script to the form, and send that to the validation script? and based on the URL, perform the update/insert?

Thanks!

Mike

  • Jackass In Charge
  • Posts: 11257
  • Karma: +168/-32
  • Ex Asshole - a better and more caring person.
Re: PHP Question
« Reply #1 on: August 14, 2007, 01:03:29 AM »
I would use a hidden value to pass along some type of key information and then do some checking to make sure they can edit that entry.

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14310
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Re: PHP Question
« Reply #2 on: August 14, 2007, 07:34:41 AM »
Unless this is a multi-form setup, why don't you just skip the insert unless the validation passes?  You have all the data to throw it back into the form so they can edit it, but it looks like you're making it harder than you have to as far as editing the data.  Maybe I'm missing something.

Mike

  • Jackass In Charge
  • Posts: 11257
  • Karma: +168/-32
  • Ex Asshole - a better and more caring person.
Re: PHP Question
« Reply #3 on: August 14, 2007, 09:00:28 AM »
I got the impression that he wasn't talking about editted rejected submissions after it has been inserted (which would be bad bad bad).  More like, you make a post and the next day you come back and edit that post.

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14310
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Re: PHP Question
« Reply #4 on: August 14, 2007, 09:33:15 AM »
Oh... well that would be completely different.

Canuck

  • Eh?!!
  • Founders
  • Posts: 792
  • Karma: +51/-3
  • Andy Moog Fan
    • My Website
Re: PHP Question
« Reply #5 on: August 14, 2007, 11:14:00 AM »
>>More like, you make a post and the next day you come back and edit that post.

Thats a good way of describing it. Coming back at any point and editing a submission.  When the user clicks edit, the info is passed to a form. I populate the form via the ULR ($_GET[]). This is the same form I use to enter a player into the database. The problem is when they submit, I wont know if its an insert/update, thats why I wanted to use the hidden field to pass a param from the edit page, letting me know an entry is being edited.

Is that a little more clear?

Thanks

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14310
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Re: PHP Question
« Reply #6 on: August 14, 2007, 11:34:45 AM »
I would just pass the id value of the entry you're trying to edit to the form and store it in a hidden field.  When you're submitting the form with a new entry, that field would be blank.

Canuck

  • Eh?!!
  • Founders
  • Posts: 792
  • Karma: +51/-3
  • Andy Moog Fan
    • My Website
Re: PHP Question
« Reply #7 on: August 14, 2007, 06:59:16 PM »
Thanks, Ill go with that approach!