Results 1 to 4 of 4

Thread: update multiple columns

  1. #1
    New Member
    Join Date
    Jun 12
    Posts
    8

    update multiple columns

    i want to update my columns with different content.

    This is my table structure

    +----+---------+
    | id | content |
    +----+---------+
    | 2 | abc |
    +----+---------+
    | 14 | def |
    +----+---------+
    From my code i am able to update only single column only.
    can anyone help me please...
    PHP Code:
    <?php
    $hostname 
    "localhost";
    $username "";
    $password "";
    $database "";

    // Connect to the database
    mysql_connect($hostname$username$password) OR DIE("Unable to connect");
    mysql_select_db("$database") or die("Unable to select database");

    if (isset(
    $_POST['ud_date'])) {
       
    $query sprintf("UPDATE test_mysql SET content='%s' WHERE id=%d",
                    
    mysql_real_escape_string($_POST['ud_date']),
                    
    2);
       if (
    mysql_query($query)) {
           echo 
    'update query succeeded';
       } else {
           else echo 
    'update query failed';
       }
    } else {
       echo 
    'please submit the form';
    }

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 02
    Posts
    21,794

    Re: update multiple columns

    There is only one column you can (or should) update.... the Content column. the ID column is your primary key, so you really shouldn't be changing that. ....so... I'm not sure what the problem is... unless there's more to the table structure that you're not telling us. Also, the use of ud_date as the ID field in the post form seems counterintuitive. I would expect something called ud_date to contain a date value...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.-I also subscribe to all threads I participate, so there's no need to pm when there's an update.*
    *Proof positive that searching the forums does work: View Thread *
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *
    * Use Offensive Programming, not Defensive Programming. * On Error Resume Next is error ignoring, not error handling(tm).
    "There is a major problem with your code, and VB wants to tell you what it is.. but you have decided to put your fingers in your ears and shout 'I'm not listening!'" - si_the_geek on using OERN

  3. #3
    New Member
    Join Date
    Jun 12
    Posts
    8

    Re: update multiple columns

    yes boss that content column only,

    i want to update that content columns with different text.

  4. #4
    Hyperactive Member xxarmoxx's Avatar
    Join Date
    Mar 07
    Posts
    365

    Re: update multiple columns

    Are you saying you want your data to look like this:

    +----+---------+
    | id | content |
    +----+---------+
    | 2 | new |
    +----+---------+
    | 14 | new |
    +----+---------+

    updating id=2 and id=14 to a new value?

Posting Permissions

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