SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Addict Chris Roane's Avatar
    Join Date
    Jul 1999
    Location
    Helena, MT
    Posts
    287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    A couple days ago I was introduced to php and mysql in Kevin's article. I have already started creating a database and everything is coming along great, except for the fact that I can't figure out how to do something that I want to do in my "Articles" administration section.

    Here are the collumns that are in my Articles table:

    ArticleDate
    ArticleText
    ArticleTitle
    ID

    The problem I am having is with editing articles. I want it so that you go to "article-admin.phtml?edaarticle" and a form will show up that asks you to put the id of the article you want to edit. I then want that form submitted to the same page with the variable "$editarticle". Now on the next page, I want a form with all the following variables already in the correct form fields: $articletext and $articletitle
    I am pretty sure that the varialbe $id is going to have to be a hidden field in that form, so that mysql knows which row to update when it is submitted. That form should then be submitted to "editarticle2", which will be on the same page and the variables will be updated in the database.

    Now, I already have written some of the php code down to do this. I would really appreciate it if I could get some people to show me how to do what I want to do.

    ------------------------------------------------------
    // Ask for ID Form
    <form Action="<?php echo($PHP_SELF); ?>" Method=Post>
    <P>Input the ID of the article you want to edit:
    <input type="text" name="id" size="5"></P>
    <Input type="submit" name="editarticle" value="SUBMIT">
    </form>

    // Form with everything in the correct fields that can be edited and submitted
    echo ("<form Action='$PHP_SELF' Method=Post>" .
    "<input type='hidden' name='id' value='$id'>" .
    "<P>Title of Article:<BR>" .
    "<input type='text' name='articletitle' size='25' value='$articletitle'></P>" .
    "<P>Article Text:<BR>" .
    "<textarea name='articletext' cols='85' rows='20' Wrap><P>$articletext</P><BR>" .
    "</textarea></P>" .
    "<Input Type=Submit Name='editarticle2' value='SUBMIT'>" .
    "</form>");
    ------------------------------------------------------

    Thanks!

    Chris Roane

    ------------------
    Web Services: DevStorm | Intersurge
    Web Tools: Web Site Resource | Free Web Site Tools

  2. #2
    Your Lord and Master, Foamy gold trophy Hierophant's Avatar
    Join Date
    Aug 1999
    Location
    Lancaster, Ca. USA
    Posts
    12,305
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I don't know PHP yet but shouldn't you have an AuthorID in your Article table? That way you can give an author proper credit and still allow multiple articles per author without duplicating author information.

    ------------------
    Wayne Luke - Sitepoint Forums Administrator
    Digital Magician Magazine - MetaQuark Creations (Coming Soon)
    sitepoint@digitalmagician.com

  3. #3
    SitePoint Addict
    Join Date
    Feb 2000
    Location
    District of Columbia
    Posts
    373
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    And just a picky little thing: you should have ArticleID instead of ID. Always try to keep naming as descriptive as possible to avoid confusion (like if you have 40 different types of ID )

    Now, I dont know PHP that well, but I think that you already have most of it in place. In the first part you are inputting an article ID, so you need an query that would look up that article ID in the database

    something like:

    SELECT articleTitle, ArticleText
    FROM <colum name>
    WHERE ID = form.id <or however you reference a form field in PHP...>

    then put those values (text and title) in the form fields.

    I think this is how its done, please dont quote me on it, I am no PHP guru, but I know how things like that are done in CF... Please correct me if I'm wrong

  4. #4
    SitePoint Addict Chris Roane's Avatar
    Join Date
    Jul 1999
    Location
    Helena, MT
    Posts
    287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wluke and Temis: I don't think it is totally necessary to do that because I am going to make a place for the author's bio right in the authortext field when we add an article, which we will add when we initially add an article to the site.

    Chris Roane

    ------------------
    Web Services: DevStorm | Intersurge
    Web Tools: Web Site Resource | Free Web Site Tools

  5. #5
    Your Lord and Master, Foamy gold trophy Hierophant's Avatar
    Join Date
    Aug 1999
    Location
    Lancaster, Ca. USA
    Posts
    12,305
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    How are you going to link the Author's with their articles though? Store all the information in the Article text? If so what if the Author's bio, URL or email address changes? They could update their profile but then your site starts to suffer from linkrot due to outdated bios stored in all those articles.

    Just something to think about.

    The query posted by Temis should work for you. Get the data out of the database then put it in the fields.

    ------------------
    Wayne Luke - Sitepoint Forums Administrator
    Digital Magician Magazine - MetaQuark Creations (Coming Soon)
    sitepoint@digitalmagician.com

  6. #6
    SitePoint Addict Chris Roane's Avatar
    Join Date
    Jul 1999
    Location
    Helena, MT
    Posts
    287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You provide a very good point, wluke. I think I am going to do that.

    Temis, I thought that you it would look like this:

    SELECT ArticleTitle, ArticleText
    From <table name>
    WHERE ID = form.id

    instead of this:

    SELECT articleTitle, ArticleText
    FROM <colum name>
    WHERE ID = form.id <or however you reference a form field in PHP...>

    Chris Roane



    ------------------
    Web Services: DevStorm | Intersurge
    Web Tools: Web Site Resource | Free Web Site Tools

  7. #7
    SitePoint Addict
    Join Date
    Feb 2000
    Location
    District of Columbia
    Posts
    373
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    of course, chris, you are absolutely right. Sorry for the typo...

  8. #8
    SitePoint Addict Chris Roane's Avatar
    Join Date
    Jul 1999
    Location
    Helena, MT
    Posts
    287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I have decided that I am going to go back and re-read Kevin's series again. I am going to start from scratch on my database because I had forgotten a lot of features that I wanted to add into certain parts when I was creating it. This time, I am sure, I will be able to do a much better job. I will definately not try to rush either.

    Thanks everyone for your input!

    Chris Roane

    ------------------
    Web Services: DevStorm | Intersurge
    Web Tools: Web Site Resource | Free Web Site Tools


Bookmarks

Posting Permissions

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