Results 1 to 10 of 10
  1. #1
    Join Date
    Dec 2008
    Location
    Florida
    Posts
    1,052

    I need some help

    I currently have two very basic scripts I've wrote, one allows you to input information and it in turn saves it to a mysql database, the other allows you to view the information currently listed in the database.

    The original script that lets you input information is a one time deal, you cannot edit it once it's there.

    I need to be able to edit the information inside the database, via a php script, once it's already been input.

    Could someone please help me/write a simple script that would do what I am trying to do?

    I'm really confused and sort of stuck...

    Thanks guys...
    Not sure what to put here :-P

  2. #2
    Join Date
    Mar 2009
    Posts
    83
    The script that pulls down the information, have it pull down the unique key for that row of data. Set this key into a hidden object, then put all of the data into form boxes. Then set a submit to a third script which queries the table with an UPDATE statement and pass the information back to it. Having the key in a hidden field will allow you to update only that row UPDATE ... WHERE ID='$key' ...

  3. #3
    Join Date
    Nov 2007
    Location
    Dallas, TX
    Posts
    8,946
    I can perhaps offer some assistance. How advanced is your programming knowledge?

    -mike
    Mike G. - Limestone Networks - Account Specialist
    Cloud - Dedicated - Colocation - Premium Network - Passionate Support
    DDoS Protection Available - Reseller Program @LimestoneInc - 877.586.0555

  4. #4
    Join Date
    Dec 2008
    Location
    Florida
    Posts
    1,052
    Quote Originally Posted by Mike - Limestone View Post
    I can perhaps offer some assistance. How advanced is your programming knowledge?

    -mike
    How often do you watch Dumb and Dumber? Lol na just kidding, I can understand it typically if I see it.

    I just sort of am completely lost on what to do with this one.

    I'd say I was beginner going on intermediate.
    Not sure what to put here :-P

  5. #5
    Join Date
    Dec 2008
    Location
    Florida
    Posts
    1,052
    Anyone? Help would be appreciated.
    Not sure what to put here :-P

  6. #6
    Join Date
    Feb 2003
    Location
    AR
    Posts
    2,381
    What does your database schema look like? Each record needs to have a unique key, perhaps called "id" which is an auto_incrementing field.

    So, visit edit.php?id=22

    edit.php should in turn do something like

    Code:
    SELECT * FROM `table` WHERE `id`=$id
    of course sanitizing $id before passing it in to the query.

    Then, in your form, in a hidden element, put the ID of the entry you're editing, ie:

    Code:
    <input type="hidden" name="id" value="$row->id" />
    Have your script POST to, say, edit_process.php

    edit_process.php will then look for the "id" field and use it in the UPDATE query, ie:

    Code:
    UPDATE `table` SET `field`='$value' WHERE `id`=$id
    That is the general idea, anyway. It should be relatively simple to take what I've written here and adapt it to your needs.

    Kevin

  7. #7
    Join Date
    Nov 2001
    Location
    Vancouver
    Posts
    2,416
    Editing data that is already in the DB isn't all that much different than inserting the db the first time. What you need is a way to determine if the data you are editing is "new" or an update.

    edit: I see Kevin (above) and I were on the same track here replying at the same time.

    Frequently a hidden database key field is used for this purpose. Let's say you have a table with some columns:

    • id - an auto-increment "identity" column
    • title - varchar, a string of some sort
    • approved - a boolean


    Your code / forms should be mostly reusable or made to be so. For an insert (create new) operation you'll populate the form values with nothing; for an update (edit existing) your form values, but including and especially the "id" field, will have values.

    You can use that "id" field to trigger different actions; once the form is submitted with an edit, if "id" contains a value your query will be an UPDATE query; otherwise it'll be an INSERT query as you have done so far.

    Personally I prefer to avoid having different URLs to access a resource merely for different actions. Regardless of the language I write an application in, I want one URL for a resource, i.e. http://theapp.com/things/something is the resource URL, always.

    http://theapp.com/things/something
    http://theapp.com/things/anotherthing
    http://theapp.com/things/thatthing

    Edit existing:
    http://theapp.com/things/something/edit
    http://theapp.com/things/anotherthing/edit
    http://theapp.com/things/thatthing/edit

    New:
    http://theapp.com/things/new

    Listing:
    http://theapp.com/things/

    The forgoing is a bit advanced if you are still dealing with edit forms, so lets go one step at a time and try to get URLs that look like:

    New:
    http://theapp.com/things.php

    Edit:
    http://theapp.com/things.php?id=something

    Delete:
    http://theapp.com/things.php?id=something
    Last edited by mwatkins; 07-04-2009 at 04:28 PM.
    “Even those who arrange and design shrubberies are under
    considerable economic stress at this period in history.”

  8. #8
    Join Date
    Dec 2008
    Location
    Florida
    Posts
    1,052
    Quote Originally Posted by mwatkins View Post
    Editing data that is already in the DB isn't all that much different than inserting the db the first time. What you need is a way to determine if the data you are editing is "new" or an update.

    edit: I see Kevin (above) and I were on the same track here replying at the same time.

    Frequently a hidden database key field is used for this purpose. Let's say you have a table with some columns:

    • id - an auto-increment "identity" column
    • title - varchar, a string of some sort
    • approved - a boolean


    Your code / forms should be mostly reusable or made to be so. For an insert (create new) operation you'll populate the form values with nothing; for an update (edit existing) your form values, but including and especially the "id" field, will have values.

    You can use that "id" field to trigger different actions; once the form is submitted with an edit, if "id" contains a value your query will be an UPDATE query; otherwise it'll be an INSERT query as you have done so far.

    Personally I prefer to avoid having different URLs to access a resource merely for different actions. Regardless of the language I write an application in, I want one URL for a resource, i.e. http://theapp.com/things/something is the resource URL, always.

    http://theapp.com/things/something
    http://theapp.com/things/anotherthing
    http://theapp.com/things/thatthing

    Edit existing:
    http://theapp.com/things/something/edit
    http://theapp.com/things/anotherthing/edit
    http://theapp.com/things/thatthing/edit

    New:
    http://theapp.com/things/new

    Listing:
    http://theapp.com/things/

    The forgoing is a bit advanced if you are still dealing with edit forms, so lets go one step at a time and try to get URLs that look like:

    New:
    http://theapp.com/things.php

    Edit:
    http://theapp.com/things.php?id=something

    Delete:
    http://theapp.com/things.php?id=something

    I sort of understood that, but I am still quite lost.

    The way I built the original code took me quite a while, I am just getting into the whole PHP programming area.

    Could someone possibly be willing to maybe type out a small code solution?

    I was seeing where kcackler was going, but I had some trouble filling in the gaps.
    Not sure what to put here :-P

  9. #9
    Join Date
    Nov 2001
    Location
    Vancouver
    Posts
    2,416
    Have a read through this tutorial:

    http://www.freewebmasterhelp.com/tutorials/phpmysql

    Download the full source for the tutorial:

    http://www.freewebmasterhelp.com/sta...ql/example.zip

    Try to follow along with that. It is important that you spend some time reading other peoples code; it'll help you gain some insight as to what you need to do to write your own.
    “Even those who arrange and design shrubberies are under
    considerable economic stress at this period in history.”

  10. #10
    Join Date
    Dec 2008
    Location
    Florida
    Posts
    1,052
    Perfect, thanks a ton mwatkins, this is exactly what I was looking for.

    I'm a hands on learner, I learn by working on it and interacting with the material. I appreciate that link a lot.
    Not sure what to put here :-P

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •