Results 1 to 2 of 2

Thread: Update multiple field in PHP/MYSQL

  1. #1
    Join Date
    Aug 2007
    Location
    Malaysia
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Update multiple field in PHP/MYSQL

    Hi,guys!I have a form need to update several fields in database,may I know what is the correct sql statement? One of the field is not editable,I just need to update other editable fields value to database. The below update statement seems went wrong.Thanks for your help...


    PHP Code:
    if ($numrow != 0)
        {// fetch each record in result set
            for ($counter = 0; $row = mysql_fetch_row($result); $counter++)
            {
                foreach ($row as $key => $value)
                {
                    if ($key == 0 || $key == 2)
                    {
    ?>
                     <td><input type = "text" name = "edited1" size = "30" value = "<?php
                        
    echo $value?>"></td>
                     <?php
                    
    }
                    else
                        if (
    $key == 1)
                        {

    ?>    
                      <td><input type ="text" size = "30" value = "<?php
                            
    echo $value?>" readonly ="readonly"></td> 
                         <?php
                        
    }
                        else
                        {
    ?>                   
                           <td><textarea name = "edited2" rows = "3"><?php
                            
    echo $value?></textarea></td>
      <?php
                        
    }
                }
            }
        }
    }

    ?>
     
                 </tr>
                </table>
                <table>
                <tr>
                <td>&nbsp;</td>
                <td width='4%'>&nbsp;</td>
                <td></tr>
                <tr>
                <td>&nbsp;</td>
                <td width='4%'>&nbsp;</td>
                <td><input type='submit' name='submit' value='Upgrade'></td>
                </table>
                </form>
                </body>
                </head>
                </html>
                
    <?php

    $tbl_name 
    "member";
    if (isset(
    $_POST['submit']))
    {
        
    $insert mysql_query("UPDATE $tbl_name SET name = '" $_POST['edited1'] . "'
                  WHERE name = '" 
    $_REQUEST['name'] . "');

  2. #2
    Join Date
    Aug 2007
    Location
    Malaysia
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I have tried the following script to update multiple field but data not save into database

    PHP Code:
    <?php

    $tbl_name 
    "member";
    if (isset(
    $_POST['submit']))
    {
        
    $update mysql_query("
                  UPDATE 
                      
    $tbl_name
                  SET
                      name = '" 
    mysql_real_escape_string($_POST['edited1']) . "',
                      telephone = '" 
    mysql_real_escape_string($_POST['edited1']) . "',
                      address = '" 
    mysql_real_escape_string($_POST['edited2']) . "'
                  WHERE
                       name = '" 
    mysql_real_escape_string($_REQUEST['name']) . "',
                       telephone = '" 
    mysql_real_escape_string($_REQUEST['telephone']) . "',
                       address = '" 
    mysql_real_escape_string($_REQUEST['address']) . "'
                  or die(mysql_error())
                  "
    );




        if (
    $update)
        {
    ?>   <script type="text/javascript">
          alert("Your profile already updated.");
          history.back();
       
         </script>
        <?php

            
    //THIS CODE IS UNCOMMENTED
            //So that people without JS can still see the message.
            
    die("Your profile already updated");
            
    //END
        
    }

    }
    ?>
    I am using action = "<? echo $HTTP_SERVER_VARS['PHP_SELF'] .
    "?frame=profile"; ?>"
    , which reflect the page(profile.php) itself.

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
  •