开发者

phpmysql update set while uploading image

I am really struggling trying to get something very simple achieved.

Essentially, I have an images table called galleryimages and a location on the server where images are stored. What I am trying to do is overwrite the source field for a given category in the table while the upload is going through.

My code will add the new image to the server, but not update the MySQL table for some reason (I can however add new lines to it although I want to keep the existing data in the table and simply change the "photo" field which locates the image).

My PHP is:

<?php include 'dbc.php'; page_protect();

    if(!checkAdmin()) {header("Location: login.php");
    exit();
    }

    $host  = $_SERVER['HTTP_HOST'];
    $host_upper = strtoupper($host);
    $login_path = @ereg_replace('admin','',dirname($_SERVER['PHP_SELF']));
    $path   = rtrim($login_path, '/\\');

    foreach($_GET as $key => $value) {
        $get[$key] = filter($value);
    }

    foreach($_POST as $key => $value) {
        $post[$key] = filter($value);
    }   
?>


<?php 
    if($_FILES['photo']) 
    {
        $target = "galleries/test/"; 
        $target = $target . basename( $_FILES['photo']['name']); 

       $title = mysql_real_escape_string($_POST['title']); 
        $pic = "galleries/test/" .(mysql_real_escape_string($_FILES['photo']['name']));
    if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) 
    {
        mysql_query("update `galleryimages` set (`title`, `photo`) VALUES ('$title', '$pic')") ;     

        echo "Success"; 
    } 
    else 
    { 
        echo "Failure"; 

    }
    } 
?> 

And the HTML is:

```html
  </head>
  <body>

        <form enctype="multipart/form-data" action="addgallery1.php" method="POST">
          <table width="100%" border="2" cellpadding="5"class="myaccount">
             <tr>
               <td>Category: </td>
               <td><select name="title" id="select8">
                  <option value="Landscape Pots">Landscape Pots</option>

                      </select></td>
            </tr>
           <tr>
               <td>Image: </td>
               <td><input type="file" name="photo" /></td>
            </tr>
             <tr>
               &l开发者_高级运维t;td colspan="2"><input type="submit" class="CMSbutton" value="Add" /></td>
             </tr>
          </table>
        </form>

        </body>
        </html>

Now I am fairly sure the problem exists in the line:

    if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) 
    {
        mysql_query("update `galleryimages` set (`title`, `photo`) VALUES ('$title', '$pic')") ;     
        echo "Success"; 
    } 

but need some help to determine if this is indeed the case - and if so how I can get it to update the MySQL table - at the moment the PHP echoes Success but does not make any update to the "photo" column in MySQL.

Hope this makes sense and one of you coding geniuses can help me resolve this - its taken me hours of trial and error but still cant get it working!!!

thanks in advance to any and all help

JD


some thing wrong here

 mysql_query("update `galleryimages` set (`title`, `photo`) VALUES ('$title', '$pic')") ;

it should be like

mysql_query("update `galleryimages` set `title`='$title', `photo`= '$pic'") ;

more info here: http://dev.mysql.com/doc/refman/5.0/en/update.html


Your MySQL query is wrong:

update `galleryimages` set `title`='$title', `photo`='$pic'

But be warned: This will update ALL rows in this table! You should add a WHERE clause to update one specific row.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜