SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Pragmatic Programmer halfasleeps's Avatar
    Join Date
    Feb 2006
    Location
    Altoona, PA. USA
    Posts
    1,945
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    problem updating images and mysql

    ive been trouble shooting this all morning and nothing ive tried has ANY different effects i just get FAILED everytime. im trying to make an admin page to update a monthly drawing. upload an image and store the image and prize name in the DB but also remove the old prize. this is what i have:


    PHP Code:
    if ($_POST["newPrize"] == 'Submit'){
        $image_name_sm = basename($_FILES['product_image_sm']['name']);
                
                
            $image_http_dir = "../../images/";
            $image = 'current_prize_'.$image_name_sm;
            $upload_http_file_sm = $image_http_dir.$image;
        
            if (copy($_FILES['product_image_sm']['tmp_name'], $upload_http_file_sm))
                ($upload_https_file_sm,$upload_http_file_sm))
                    $temp_upd['product_image_sm'] = $image_name_sm;
                    chmod($upload_http_file_sm,0755);
                                                    ######update DB####
                    $prize = $_POST['prize'];
                    ($upload_http_file_sm); 
                     


                    mysql_query("DELETE FROM monthly_prize WHERE id = '1'");
                    mysql_query("INSERT INTO monthly_prize SET image ='".$image."', prize = '".$prize."'");
                            
                                }else{
            echo "FAILED";
                }
                }
    ?>
    <table width="100%"  border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td colspan="5"><div align="left"><span class="style2">
            &nbsp;Home Page Scrolling Images </span></div>      
          <span class="style3">
          </span></td>
      </tr>
      <tr>
        <td colspan="4">
          <div align="center">&nbsp; </div></td>
        <td>&nbsp;      </td>
      </tr>
      <?php
      $result 
    mysql_query('SELECT * FROM monthly_prize');
      while (
    $row mysql_fetch_assoc($result)){
              
    $prize $row['prize'];
            
    $image $row['image'];
        }
      
    ?>
      <tr>
                    <td>&nbsp;</td>
                    <td colspan="3"><form name="form0" method="post" action="">
                    <img src="../../images/<?=$image?>" width="75" height="75" />
                        Image
                        <input name="product_image_sm" id="product_image_sm" type="file" size="20" value="<?=$image?>">
                        Prize
                        <input name="prize" type="text" size="40" value="<?=$prize?>">
                        <input type="submit" name="newPrize" value="Submit"></form></td>
                    <td>&nbsp;</td>
                     </tr>
    Altoona Design
    Freelance Flex developer for hire.
    ActionScript Programmer with 8 Years Experience.

  2. #2
    Pragmatic Programmer halfasleeps's Avatar
    Join Date
    Feb 2006
    Location
    Altoona, PA. USA
    Posts
    1,945
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok now i am trygin to just make it SAY the current prize and its STILL not working???

    PHP Code:
    if ($_POST["newPrize"] == 'Submit'){

                    $prize = $_POST['prize'];
                    //$tmp = getimagesize($upload_http_file_sm);
                     echo $prize;


                    mysql_query("DELETE FROM monthly_prize WHERE id = '1'");
                    mysql_query("INSERT INTO monthly_prize SET prize = '".$prize."'");
                            
                }    
    ?>
    <table width="100%"  border="0" cellspacing="0" cellpadding="0">
        <?php
      $result 
    mysql_query('SELECT * FROM monthly_prize');
      while (
    $row mysql_fetch_assoc($result)){
              
    $prize $row['prize'];
        }
      
    ?>
      <tr>
                    <td>&nbsp;</td>
                    <td colspan="3"><form name="form0" method="post" action="">
                        Current Monthly Prize
                        <input name="prize" type="text" size="40" value="<?=$prize?>">
                        <input type="submit" name="newPrize" value="Submit"></form></td>
                    <td>&nbsp;</td>
                     </tr>

    i made it echo $prize and that comes out fine exactly what i typed in, but the form field nor the DB gets changes it just stays the same
    Altoona Design
    Freelance Flex developer for hire.
    ActionScript Programmer with 8 Years Experience.

  3. #3
    SitePoint Evangelist chiphunt1's Avatar
    Join Date
    Oct 2003
    Location
    louisville, ky
    Posts
    436
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your first problem is this code:

    <form name="form0" method="post" action="">

    Perhaps you should try:

    <form name="form0" method="post" action="" enctype="multipart/form-data">
    Calm down -- it's only ones and zeroes

  4. #4
    Pragmatic Programmer halfasleeps's Avatar
    Join Date
    Feb 2006
    Location
    Altoona, PA. USA
    Posts
    1,945
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok i changed:
    mysql_query("DELETE FROM monthly_prize WHERE id = '1'");
    to:
    mysql_query("DELETE FROM monthly_prize WHERE id = '0'");

    and apparently that did the trick, because the default for an auto_increment starts at 0 not 1.
    Altoona Design
    Freelance Flex developer for hire.
    ActionScript Programmer with 8 Years Experience.


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
  •