如何在MYSQL(数据库)上更新我的Bio?

时间:2016-08-06 10:15:17

标签: php

更新页面。

<?php


        if(isset($_FILES['profile']) === true){
            if(empty($_FILES['profile']['name'])===true){
                echo 'Please Choose a file';
            }else{
                $allowed = array ('jpg','jpeg','gif','png');
                $file_name = $_FILES['profile']['name'];
                $file_extn = strtolower(end(explode('.',$file_name)));
                $file_temp = $_FILES['profile']['tmp_name'];

                if (in_array($file_extn, $allowed)===true){
                    change_profile_image(($_SESSION['accts_id']), $file_temp, $file_extn);
                    header('Location'. $current_file);
                }else{
                    echo 'Incorret file type. Allowed: ';
                    echo implode(', ', $allowed);
                }
            }
        }




        $firstname = getuserfield('firstname');
        $profile = getuserfield('Profile');

        if(empty($profile ===false)){
            echo '<img src="', $profile,'" alt="',$firstname,'\'s Profile Image">';
        }

        if(isset($_POST['textarea'])){
            $textarea = $_POST['textarea'];
            if(!empty($_POST['textarea'])){

            change_bio_details($_SESSION['accts_id'], $textarea);
            header('Location'. $current_file);
        }else
        {
            echo 'Please enter data';
        }

        }

    ?>

functionpage。

function change_profile_image($accts_id, $file_temp, $file_extn) {
    $file_path ='imageuploaded/profile/'. substr (md5(time()), 0,10). '.'. $file_extn; 
    move_uploaded_file($file_temp, $file_path);
    $sql = "UPDATE `accts` SET `Profile` ='". mysql_real_escape_string($file_path) . "' WHERE `id` =" . (int)$accts_id; 
    mysql_query($sql);
}

function change_bio_details($accts_id, $textarea){
    $sql = "UPDATE `accts` SET `Bio` ='".$textarea."' WHERE `id = ". (int)$accts_id;
    mysql_query($sql);
}

2 个答案:

答案 0 :(得分:0)

首先创建输入文件,然后

获取该文件并使用新图像的URL更新您的MySQL

如果您想在此处查看代码评论,我可以解释一下

答案 1 :(得分:0)

您上次更新查询中有一个简单的拼写错误:

$sql = "UPDATE `accts` SET `Bio` ='".$textarea."' WHERE `id = ". (int)$accts_id;

在&#39; id&#39;

之后,你错过了一个
....WHERE `id` = "....