SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey all...I am in the process of working on a admin tool for a trial site I am buildin. The site is PHP/mySQL based. I would like to be able to add, edit and delete an entry. Could someone point the way to code that I can adapt or post code I could use as a basis for my test page?

    cheers.
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  2. #2
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is a very broad question, but the basic logic would be to populate a drop-down menu with a simple SELECT statement where the value of each option is the ID - the unique identifer for each record.

    From there, it's all simple DELETE/EDIT/SELECT statements used to set the value of forms.

  3. #3
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry TWT. I should have been more spcific. I want to "build" a drop down list of the existing items as well as give the option of adding or deleting an item.

    THe main thing is I have hardly any experience with forms. I can build them easily, but I am still a bit unclear on the extra stuff needed to make a form work. That is the hard part for me. I think that if I got one easy example, then I could do anything else that was needed. The scripting part would be easy as I can already do that part.
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  4. #4
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You'll need to be more specific - what part of the form is troubling you, specifically?

  5. #5
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK...

    1) I don't really know how to specify the "values" for a field.

    2) I don't know how to create an insert statement using a form.

    3) I don't know what hidden fields are for. Would I need to use them?

    I am just lacking in the forms department. I have trouble understanding how they operate. Does that help?
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  6. #6
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Firstly: Here's how you create a regular form field with a variable contained inside:

    <input type="text" name="email" value="<?php echo($email); ?>

    Secondly: If you don't know how to create an SQL insert statement, you'll have to read Kevin's tutorial - I can't re-invent his wheel here, and even if I were to try, it wouldn't be as useful as what Kevin already has up.

    Thirdly: Hidden fields work the same way, only you specify the TYPE as "hidden" instead of "text" - pretty simple.

    I believe http://www.htmlgoodies.com has some tutorials on forms as well.

  7. #7
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok...I think I might be making this too hard for me and you guys. I do know how to create an INSERT statement, I just haven;t used them that much. I have been focusing mroe on getting data OUT of a DB than trying to put stuff into one. That is why I am asking about admin pages.

    All I really want to see is one example of a page, then I can riff off of that and create any other page I need. For example. Here is a page that I have created.

    http://www.gravitydigital.com/misc_uploads/updates.html

    It successfully pulls the correct information from the DB, know I just need to know the proper way to get information that I give it into the DB. Does that make more sense? I guess I am not as bad with forms as I made out. It's just that some of the info doesn't make sense.
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  8. #8
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Kevin Yank's PHP/MySQL articles pretty much cover most of what you want to do. Have you read through them yet?

    http://www.webmasterbase.com/article.php?aid=228&pid=0

  9. #9
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok..... here goes nothin... this is my guess at what you're looking for.

    Code:
    <?php
    
    // Include file for database connection, or put the code
    // here
    
    
    // Table name
    $table = "mytable";
    
    echo("Edit:<input type=\"radio\" name=\"action\" value=\"edit\"><br>Delete:<input type=\"radio\" name=\"action\" value=\"delete\"><br>");
    
    echo("<form action=\"edit_delete.php\" method=\"post\">");
    $query = "SELECT * FROM $table";
    $result = mysql_query($query);
    
    echo("<input type=\"hidden\" name=\"table\" value=\"$table\"><select size=\"1\" name=\"myresults\">");
    
    while($row = mysql_fetch_array($result))
    {
    	$id = $row['ID'];
    	$myresults = $row['myresults'];
    
    echo("<option value=\"$id\">$myresults");
    
    }
    
    echo("</select><br><input type=\"submit\" name=\"edit_delete\" value=\"Go\"></form><p>");
    Use the hiden name "table" if you have to use another page to edit/delete the script. The way that I have it coded, I used an outside page. I would however, in a normal situation have it be

    Code:
    <form action=\"$PHP_SELF\" method=\"POST\">
    Use if to delete and edit...

    Code:
    if($edit_delete == "Go"){
    
    if($action == "delete"){
    
    // Delete from database where table is $table and
    // ID is $myresults
    
    echo("It has been deleted");
    
    }
    
    if($action == "delete"){
    
    // Select from $table where id is $myresults
    
    // Display in form
    
    }
    
    // End if $edit_delete
    }
    Hope this might help some. You will want to edit my arrays to match your tables. I suggest reading Kevin's tutorial, don't skip over anything, and you will get it!

    I just read that a few weeks ago, and already really understand PHP/MySQL. (In fact I have built an entire site out of it... need is the best teacher)

    God Bless, let me know if this just made it harder for you to understand.

    Alex
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

  10. #10
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    alright...I tried adding in some of your code, exbabylon, but I am still having some troubles. The page now pulls in everything correctly. This is a sample line form the drop-down list.

    <form action="news_items.php3" method="post">
    Editinput type="radio" name="action" value="edit">
    Deleteinput type="radio" name="action" value="delete">
    <select size="1" name="news_item">
    <option value="00001">True Tunes Interviews Plus One</option>

    That is what is should be. Now how do I translate that into edit? What I mean is, how do I pass the ID to the next page so that the next page knows what story to edit? Another question along the same lines is, should I have the entire form setup in two branches of an IF statement?

    like this:?

    if (!isset($id)) {
    show the form with the fields empty
    } else {
    show the forms with the fields populated with whatever the ID is.
    }
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  11. #11
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry... I botched the code... here's one way... it's just the fixed version of my last code sniplet.

    Code:
    if($edit_delete == "Go"){
    
    if($action == "delete"){
    
    // Delete from database where table is $table and
    // ID is $myresults
    
    echo("It has been deleted");
    
    }
    
    if($action == "edit"){
    
    // Select from $table where id is $myresults
    
    // Display in form
    
    }
    
    // End if $edit_delete
    }
    if you use the isset(id) you will have a few complications unless you really know how to do it if you get into a really complex program.

    just use the

    Code:
    if($submit == "Go"){
    with all the rest of the functions below it.... the form passes along an edit or delete value for the name action (the radio buttons). This can be used very easy to manipulate things.


    let me know if this helped... basicly, what is going on with forms is this.

    If you have every used a variable in PHP then you know how to use forms. All the form does is add user input. The name of the form provides you with the variable, and the user input (in text boxes and textarea's) and what you choose (checkboxes, hidden, radio). These can all be used to manipulate the forms to do whatever function/purpose you choose.
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services


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
  •