SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict
    Join Date
    Feb 2003
    Location
    durango
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Updating Multiple Records at a Time

    I know that this has been addressed a few times on this board but I can't find the exact answer that I am looking for and I have played with this long enough. So... I want to do a simple update that will allow me to modify one field on more than one row in my table. It should look at the userID and then update that record. Here are my form fields:

    HTML Code:
     
    <input name="process[]" type="checkbox" id="process[]" value="<?php $value ?>" />
    <input name="userID[]" type="hidden" id="userID[]" value="<?php $userID ?>" />
    Here is the php that should process the form:

    PHP Code:
     
    $process 
    $_POST["process"];
    $userID $_POST["userID"];
     
    for (
    $i=0$i<$count$i++)
    {
    $sql "UPDATE donate SET don_process = '$process[$i]' WHERE don_userid = '$userID[$i]'";
    mysql_query($sql$connection) or die(mysql_error()); 

    Any Ideas?

    Thanks,

  2. #2
    Mal Reynolds Mandibal's Avatar
    Join Date
    Aug 2003
    Location
    Columbus
    Posts
    718
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what problem are you running into here? I'm not saying there isnt something wrong with your code but there is nothing that stands out as immediately being bad. And explain what your trying to do a little more. Finally, is the form you posted just a small part of it? I'm confused why your using "userID[]" on what looks like a single hidden field? Thanks
    Erh

  3. #3
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,608
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    $count what? In your script $count is nothing.
    Ian Anderson
    www.siteguru.co.uk

  4. #4
    SitePoint Addict
    Join Date
    Feb 2003
    Location
    durango
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Mandibal,

    Thanks for the reply,

    1) The problem is that it is not updateing anything. I run the update and then view the database to double check and nothing has changed. I basically want to mark these records as "processed" with a single checkbox. My database records a "0" by default when the record is created and then the user logs in, processes the records by hand and then marks them as processed. That is supposed to change the "0" to a "1".

    2) There isn't much to the form. I am using Dreamwever to display the all of the records in a "repeat region". All of that sits in a HTML table. The table sits inside a Form tag. Those are the only two fields, but each row (up to 15) will have the same two fields. The userID is a unique ID that comes from the database.

    Thanks

  5. #5
    SitePoint Addict
    Join Date
    Feb 2003
    Location
    durango
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    siteguru

    Thanks, that was one problem. I added

    $count = count($_POST["process"]);

    Now the script does do an Update, but it isn't updating the right record. If I update them all then it works fine, but if I just do the first one then it actualy updates the second record. Very strange.

  6. #6
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,608
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    $count = count($_POST["process"]) - 1;

    The first index is 0, count gives you then number of elements (so a single element array has a count of 1).
    Ian Anderson
    www.siteguru.co.uk


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
  •