Results 1 to 8 of 8

Thread: [RESOLVED] edit something from db

  1. #1

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Resolved [RESOLVED] edit something from db

    hey there,

    how do i go about editing something form a db. It was added to from a form and submitted.

    thanks in advanced!
    My usual boring signature: Something

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: edit something from db

    PHP Code:
    mysql_query("UPDATE addressbook SET name='newname', address='newaddress' WHERE name='david' AND phonenumber='555-5555' LIMIT 1"); 
    all of this stuff is outlined in this post and already has all the information you've been asking for lately.
    Like Archer? Check out some Sterling Archer quotes.

  3. #3

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: edit something from db

    yeah, but i want to have it taken from the db, put into a form to be edited then put back into the db.
    My usual boring signature: Something

  4. #4
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: edit something from db

    query the database before you make the form and get the fields you want and save them to a variable.. for example:
    PHP Code:
    <?php
      $olddata_query 
    mysql_query("SELECT fieldname1, fieldname2 FROM tablename WHERE id=12313 LIMIT 1");
      
    $olddata mysql_fetch_array($olddata_query);
    ?>
    <!-- print your form -->
    now, for each <input> or <textarea> that you have, put the corresponding field name into that objects "value." for example:
    PHP Code:
    <!-- this is for an <INPUT> tag -->
    <input type="text" name="fieldname1" value="<?php echo $olddata['fieldname1']; ?>">

    <!-- this is for a <TEXTAREA> tag -->
    <textarea name="fieldname2"><?php echo $olddata['fieldname2']; ?></textarea>
    Then, just submit it and update like I posted above.
    Like Archer? Check out some Sterling Archer quotes.

  5. #5

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: edit something from db

    cool! works. now, how do i put in the UPDATE code into my exsting code, here it is:
    PHP Code:
    <?php 
                       $db 
    mysql_connect('localhost''homtek_dclamp''password') or die(mysql_error()); 
                
    mysql_select_db('homtek_homtek'$db) or die(mysql_error()); 
                
    $olddata_query mysql_query("SELECT subject, news FROM news WHERE news_id='".$_GET['id']."' LIMIT 1"); 
                
    $olddata mysql_fetch_array($olddata_query); 
                
    ?> 
                <!-- print your form --> 
                <form action="add_news.php" method="POST">
                Subject:<br>
                <input type="text" name="subject" value="<?php echo $olddata['subject']; ?>"><br><br>
                News Content:<br>
                <textarea columns=5 rows=10 name="content"><?php echo $olddata['news']; ?></textarea> 
                <input type="hidden" name="poster" value="<?PHP echo $logged_in_admin?>">
                <input type="hidden" name="date" value="DATE_HERE">
                <input type="submit" value="Submit"> <input type="reset" value="Reset Form">
                </form>
    Last edited by dclamp; Oct 10th, 2006 at 11:40 PM.
    My usual boring signature: Something

  6. #6
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: edit something from db

    you have to put the update query in your add_news script, not that one.
    Like Archer? Check out some Sterling Archer quotes.

  7. #7

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: edit something from db

    i actualy made a error on that. when i send it to that it just adds it as a new post. so it would have to go to another one. should i just make a new page? or is there a way that i can put it there?
    My usual boring signature: Something

  8. #8
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: edit something from db

    well, you can always use GET requests and change the form action to:

    add_new.php?edit=true

    then, in the add_new.php you will just have to check the value of $_GET['edit'] and if it's true, then you know you need to edit a post instead of make a new one. this could get somewhat complex (although, if you know what you're doing it could be pretty simple too), so it would be easier to just make a separate script that edits.
    Like Archer? Check out some Sterling Archer quotes.

Posting Permissions

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



Click Here to Expand Forum to Full Width