doupu3635 2013-07-07 17:01
浏览 30

如何在没有更新映像的情况下更新mysql中的数据

I want to update my data in mysql. But, if i want update (ex. firstname), photo_profile will lost.

 <?php
    include 'function_page_user.php';

    if(($_FILES['photo_profile']) and ($_POST['firstname']) and ($_POST['lastname']) and ($_POST['password']))
    {
        session_start();

        include 'connect.php';
        $foldername="assets/img/user/";
        $firstname = mysql_real_escape_string($_POST["firstname"]);
        $lastname = mysql_real_escape_string($_POST["lastname"]);
        $pwd = mysql_real_escape_string($_POST["password"]);

        if((!empty($firstname) and !empty($lastname) and !empty($pwd)) and($_FILES['photo_profile']))
        {
            $image = $foldername . basename ($_FILES['photo_profile'] ['name']);
            mysql_query ("update user set firstname = '".$firstname."' , lastname = '".$lastname."' , password = '".$pwd."' , photo_profile='".$image."' where id_user ='".$_SESSION['id']."'");
            move_uploaded_file($_FILES['photo_profile']['tmp_name'], $image);
            echo "<script>alert ('File Succes To edit');</script>";
            $page="formubahuser.php";

            echo redirectPage($page);   
        }
        else echo "variabel empty";
    }
    else 
        echo ("your data is not complete<a href=formubahuser.php>Fill it again</a>");
?>
  • 写回答

1条回答 默认 最新

  • douzengjian1535 2013-07-07 17:22
    关注

    You have a number of major problems in your code. Before you continue, you need to read about the following topics:

    1) The php mysql_ functions have been deprecated. That means the functions will be removed in future versions of php. You should use pdo or mysqli instead

    2) When you store passwords in your database, they should always, always, always be encrypted.

    Regarding your question, I think you are asking how to change the metadata (such as a firstname) without unsetting the photo url. Try something like this:

    $updatequery = "UPDATE user SET firstname = '".$firstname."' , lastname = '".$lastname."' , password = '".$pwd."'";
    if( $_FILES['photo_profile'])
    { 
       $image = $foldername . basename ($_FILES['photo_profile'] ['name']);
       $updatequery .= ", photo_profile='".$image."'"; 
    }
    $updatequery .= " where id_user ='".$_SESSION['id']."'";
    
    评论

报告相同问题?

悬赏问题

  • ¥100 iOS开发关于快捷指令截屏后如何将截屏(或从截屏中提取出的文本)回传给本应用并打开指定页面
  • ¥15 unity连接Sqlserver
  • ¥15 图中这种约束条件lingo该怎么表示出来
  • ¥15 VSCode里的Prettier如何实现等式赋值后的对齐效果?
  • ¥15 流式socket文件传输答疑
  • ¥20 keepalive配置业务服务双机单活的方法。业务服务一定是要双机单活的方式
  • ¥50 关于多次提交POST数据后,无法获取到POST数据参数的问题
  • ¥15 win10,这种情况怎么办
  • ¥15 如何在配置使用Prettier的VSCode中通过Better Align插件来对齐等式?(相关搜索:格式化)
  • ¥100 在连接内网VPN时,如何同时保持互联网连接