SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: help query

  1. #1
    SitePoint Evangelist
    Join Date
    Dec 2006
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    help query

    Hi Guys,

    this query looks a bit overcomplicated , what im trying to do is if an upload field (is left blank) the only thing inserted into mysql is the fields that are filled in e.g

    if i upload file 12 and 5 only 1,2 and 5's location is stored in mysql i was thinking of this:

    PHP Code:
          $upload_query "UPDATE `users` ";
          
    ## if h1 ##########################################################################
          
    if(empty($headshot1)) {
          
          echo 
    '';
          
          } else {
          
          echo 
    "SET `headshot_1`='$renamed_photo_1'";
          
          }
          
          if(empty(
    $headshot2)) {
          
          echo 
    '';
          
          } else {
          
          echo 
    ",`headshot_2`='$renamed_photo_2',";
          
          }
          
          if(empty(
    $headshot3)) {
          
          echo 
    '';
          
          } else {
          
          echo 
    "`headshot_3`='$renamed_photo_3',";
          
          }
          
          if(empty(
    $headshot4)) {
          
          echo 
    '';
          
          } else {
          
          echo 
    "`headshot_4`='$renamed_photo_4',";
          
          }
          
          if(empty(
    $headshot5)) {
          
          echo 
    '';
          
          } else {
          
          echo 
    "`headshot_5`='$renamed_photo_5',";
          
          }
          
          
    $upload_query .= "WHERE `username`='$member'";
          
    $upload_result mysql_query($upload_query) or die (mysql_error()); 
    does this look ok at all or have i went overboard with th equery?

    thanks guys

    Graham

  2. #2
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dont go like that too complicated. Just create your form like this:
    HTML Code:
    <form action="" method="post" enctype="multipart/form-data" name="frm">
    <table width="700" border="0" align="left" cellpadding="2" cellspacing="1" style="border:1px #999999 solid;">
      <tr>
        <td colspan="4" bgcolor="#999999">&nbsp;</td>
      </tr>
      <?php for($i = 0; $i < 10; $i++){?>
      <tr>
        <td width="83">Caption # <?php echo $i+1;?></td>
        <td width="221"><input name="cap[]" type="text" id="cap[]"></td>
        <td width="84">File # <?php echo $i+1;?></td>
        <td width="312"><input name="file[]" type="file" id="file[]"></td>
      </tr>
      <?php
      }
      ?>
      <tr>
        <td>&nbsp;</td>
        <td colspan="2">&nbsp;</td>
        <td><input type="submit" name="Submit" value="Submit"></td>
      </tr>
    </table>
    </form>
    And your PHP will be like this:
    PHP Code:
    if($_POST['Submit']){
        for(
    $j 0$j 10$j++){
            if(
    is_uploaded_file($_POST['file']['tmp_name'][$j])){
                
    // upload your file and insert data $_POST[cap][$j] for caption
            
    }
        }

    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5


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
  •