Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Apr 2003
    Location
    Matewan, WV
    Posts
    201
    Thanks
    0
    Thanked 1 Time in 1 Post

    Like named fields updating at same time

    Take results from query, allow individual row information to be changed (while view several columns)
    Once you peek at the code, you'll understand what I'm doing. For some reason, though, it's not working. It doesn't seem to return any error, either. I don't know what else to do, really...it's probably something simple I'm missing..

    --
    username is already defined
    PHP Code:
    <?
    // Connect database.
    $sql="SELECT * FROM media WHERE username='$username' AND flagged='1' AND description='' ORDER BY dateadded DESC";
    $result=mysql_query($sql) or die(mysql_error()); 

    // Count table rows
    $count=mysql_num_rows($result);
    ?>
    <table width="95%" border="0" cellspacing="1" cellpadding="0">
    <form name="form1" method="post" action="<? echo $_SERVER['PHP_SELF']; ?>">
    <tr>
    <td>
    <table width="95%" border="0" cellspacing="1" cellpadding="0">
    <?php
    while($rows=mysql_fetch_array($result)){
    ?>
    <tr>
    <td align="center"><? $id[]=$rows['id']; ?><? echo $rows['id']; ?><br><a href="thumb.php?src=<? echo $rows['imagename']; ?>&x=600&y=600&f=0"><img src="thumb.php?src=<? echo $rows['imagename']; ?>&x=200&y=200&f=0"></a></td>
    <td align="center"><center><input name="description[]" type="text" id="description" value="<? echo $rows['description']; ?>"><br><b><? echo $rows['dateadded']; ?></b><br><? echo $rows['gallery']; ?></center></td>
    </tr>
    <?php
    }
    ?>
    <tr>
    <td colspan="2" align="center"><input type="submit" name="Submit" value="Submit"></td>
    </tr>
    </table>
    </td>
    </tr>
    </form>
    </table>
    <?php
    if($Submit){
    for(
    $i=0;$i<$count;$i++){
    $sql1="UPDATE media SET description='$description[$i]' WHERE id='$id[$i]'";
    $result1=mysql_query($sql1) or die(mysql_error()); 
    }
    }

    if(
    $result1){
    header("location:wizard3.php");
    }

    mysql_close();
    }
    ?>
    <3 CF

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Two possible options I can think of off the top of my head.
    The first one is that it is actually updating, but because you are extracting the information to show first before updating you don't see the changes until you reload.
    The seconds is the most likely problem: register_globals. By default, register globals are disabled in PHP, meaning $Submit and $description don't actually exist. You can test this by echoing out from the if ($submit) clause.
    Instead, try like so:
    PHP Code:
    if($Submit){
    for(
    $i=0;$i<$count;$i++){
    $sql1="UPDATE media SET description='$description[$i]' WHERE id='$id[$i]'";
    $result1=mysql_query($sql1) or die(mysql_error()); 
    }
    }

    if(
    $result1){
    header("location:wizard3.php");
    }

    mysql_close();

    becomes:
    PHP Code:
    if (isset($_POST['Submit']))
    {
        for (
    $i 0$i $count$i++)
        {
            
    $desc mysql_real_escape_string($_POST['description'][$i]);
            
    $sql='UPDATE media SET description=\'' $desc '\' WHERE id=' . (int)$id[$i];
            
    mysql_query($sql) OR die(mysql_error());
        }
        
    mysql_close();
        
    // Don't need to capture anything, since any errors will be trapped in a die.
        
    header("Location: wizard3.php");
    }
    mysql_close(); 
    On a side note, I believe that mysql supports multiple updates. This means you can go like so:
    Code:
    for (...) 
    {
        $qry .= 'UPDATE media SET description=\'' . $desc . '\' WHERE id = ' . (int)$id[$i] . ';';
    }
    mysql_query($qry);
    If I'm not mistaken.

    Edit:
    I made a horrible assumption as well. The ID that you use is an integer value in the code that I used, if its not, you will need to filter it through a mysql_real_escape_string as well and drop the (int) typecasting.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Posting Permissions

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