Results 1 to 4 of 4

Thread: update multiple columns

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2012
    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 2002
    Posts
    34,687

    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 don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * 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??? *

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 2012
    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 2007
    Posts
    378

    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
  •  



Click Here to Expand Forum to Full Width