#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    8
    Rep Power
    0
    Hey everyone,

    I was hoping someone could help me. This is what I want to do:

    I want to make it so that when someone enters text into a form, the text is entered into a mysql database. However, the way I want it to work is, when the person enters text into that field at a later date, it updates it instead of adding another row in the db.

    Can someone please tell me the easiest way to do this? Thanks.

    Sorry about the bad wording.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    36
    Rep Power
    15
    <form method="post" action=" <?php echo $PHP_SELF ?>">
    <br>
    Your text<br>
    <input type="Text" name="your var" size="30">
    Enter your ID<br>
    <input type="Text" name="id" size="30"> </form>

    <?php
    $hostname = "localhost";
    $username = "your username";
    $password = "your password";
    $dbName = "your database";
    $userstable = "your table";

    if ($submit) {
    MYSQL_CONNECT($hostname,$username,$password) OR DIE("Unable to connect to database");

    @mysql_select_db("$dbName") or die("Unable to select database");
    $result = mysql_query ("SELECT * FROM $userstable WHERE id = '$id'");

    $query = "REPLACE INTO $userstable SET your table colum name = '$your var'";
    $result = MYSQL_QUERY($query);
    }

    ?>

    Put this in your html this will work to update an exsisting record you will have to adapt this to your needs. I hope this helps you


    ------------------
    good luck Dr.E.L.

    [This message has been edited by Dr_E_lectric (edited June 02, 2000).]

    [This message has been edited by Dr_E_lectric (edited June 02, 2000).]
  4. #3
  5. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,642
    Rep Power
    4492
    I don't see the reason for that first mysql_db_query statement with the SELECT.

    Instead of REPLACE, you can also use UPDATE:

    mysql_db_query("UPDATE $table SET text='$input_text' WHERE id='$id'");

    ---John Holmes
    ---www.SepodatiCreations.com

Similar Threads

  1. Replies: 5
    Last Post: July 29th, 2011, 09:21 PM
  2. (mysql) retrieving 1 row instead of 40 rows
    By ol4pr0 in forum PHP Development
    Replies: 8
    Last Post: January 30th, 2004, 03:22 PM
  3. specific row with mysql
    By glassgorilla in forum PHP Development
    Replies: 8
    Last Post: January 28th, 2004, 10:05 AM
  4. outputing mysql rows for users
    By alenka99 in forum MySQL Help
    Replies: 2
    Last Post: January 16th, 2004, 02:37 PM
  5. Updating table rows in MySQL
    By Lueking in forum MySQL Help
    Replies: 1
    Last Post: January 11th, 2004, 12:21 PM

IMN logo majestic logo threadwatch logo seochat tools logo