Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何将个人资料照片上载器添加到预先存在的表单和数据库_Php_Html_Mysql - Fatal编程技术网

Php 如何将个人资料照片上载器添加到预先存在的表单和数据库

Php 如何将个人资料照片上载器添加到预先存在的表单和数据库,php,html,mysql,Php,Html,Mysql,拜托,我是php新手,我正在尝试编写一个注册表,用户也可以上传他们的个人资料图像。表单的其他部分工作正常,只是上传方面让我头疼。我已经搜索了很多论坛,但没有一个能给我问题的答案 当我的笔记本电脑连接上时,我会发布我以前的代码,因为这里的服务器非常慢 我将感谢任何帮助,请,我只想在数据库中存储的图像名称,我不需要任何其他属性的图像。图像应上传到特定的文件夹/目录。而且图像名称也应该更改,所以它是我想存储在数据库中的新名称 提前谢谢 下面是我的脚本: <?php //We check if t

拜托,我是php新手,我正在尝试编写一个注册表,用户也可以上传他们的个人资料图像。表单的其他部分工作正常,只是上传方面让我头疼。我已经搜索了很多论坛,但没有一个能给我问题的答案

当我的笔记本电脑连接上时,我会发布我以前的代码,因为这里的服务器非常慢

我将感谢任何帮助,请,我只想在数据库中存储的图像名称,我不需要任何其他属性的图像。图像应上传到特定的文件夹/目录。而且图像名称也应该更改,所以它是我想存储在数据库中的新名称

提前谢谢

下面是我的脚本:

<?php
//We check if the user is logged
if(isset($_SESSION['username']))
{
//We check if the form has been sent
if(isset($_POST['username'], $_POST['password'], $_POST['passverif'], $_POST['email'], $_POST['avatar']))
{
    //We remove slashes depending on the configuration
    if(get_magic_quotes_gpc())
    {
        $_POST['username'] = stripslashes($_POST['username']);
        $_POST['password'] = stripslashes($_POST['password']);
        $_POST['passverif'] = stripslashes($_POST['passverif']);
        $_POST['email'] = stripslashes($_POST['email']);
        $_POST['avatar'] = stripslashes($_POST['avatar']);
    }
    //We check if the two passwords are identical
    if($_POST['password']==$_POST['passverif'])
    {
        //We check if the password has 6 or more characters
        if(strlen($_POST['password'])>=6)
        {
            //We check if the email form is valid
            if(preg_match('#^(([a-z0-9!\#$%&\\\'*+/=?^_`{|}~-]+\.?)*[a-z0-9!\#$%&\\\'*+/=?^_`{|}~-]+)@(([a-z0-9-_]+\.?)*[a-z0-9-_]+)\.[a-z]{2,}$#i',$_POST['email']))
            {
                //We protect the variables
                $username = mysql_real_escape_string($_POST['username']);
                $password = mysql_real_escape_string($_POST['password']);
                $email = mysql_real_escape_string($_POST['email']);
                $avatar = mysql_real_escape_string($_POST['avatar']);
                //We check if there is no other user using the same username
                $dn = mysql_fetch_array(mysql_query('select count(*) as nb from users where username="'.$username.'"'));
                //We check if the username changed and if it is available
                if($dn['nb']==0 or $_POST['username']==$_SESSION['username'])
                {
                    //We edit the user informations
                    if(mysql_query('update users set username="'.$username.'", password="'.$password.'", email="'.$email.'", avatar="'.$avatar.'" where id="'.mysql_real_escape_string($_SESSION['userid']).'"'))
                    {
                        //We dont display the form
                        $form = false;
                        //We delete the old sessions so the user need to log again
                        unset($_SESSION['username'], $_SESSION['userid']);
?>
<div class="message">Your were successfully Updated. You need to log again.<br />
<a href="connexion.php">Log in</a></div>
<?php
                    }
                    else
                    {
                        //Otherwise, we say that an error occured
                        $form = true;
                        $message = 'An error occurred while updating your informations.';
                    }
                }
                else
                {
                    //Otherwise, we say the username is not available
                    $form = true;
                    $message = 'The username you want to use is not available, please choose another one.';
                }
            }
            else
            {
                //Otherwise, we say the email is not valid
                $form = true;
                $message = 'The email you entered is not valid.';
            }
        }
        else
        {
            //Otherwise, we say the password is too short
            $form = true;
            $message = 'Your password must contain at least 6 characters.';
        }
    }
    else
    {
        //Otherwise, we say the passwords are not identical
        $form = true;
        $message = 'The passwords you entered are not identical.';
    }
}
else
{
    $form = true;
}
if($form)
{
    //We display a message if necessary
    if(isset($message))
    {
        echo '<strong>'.$message.'</strong>';
    }
    //If the form has already been sent, we display the same values
    if(isset($_POST['username'],$_POST['password'],$_POST['email']))
    {
        $pseudo = htmlentities($_POST['username'], ENT_QUOTES, 'UTF-8');
        if($_POST['password']==$_POST['passverif'])
        {
            $password = htmlentities($_POST['password'], ENT_QUOTES, 'UTF-8');
        }
        else
        {
            $password = '';
        }
        $email = htmlentities($_POST['email'], ENT_QUOTES, 'UTF-8');
        if(isset($avatar))
    {
        $avatar = htmlentities($_POST['avatar'], ENT_QUOTES, 'UTF-8');
    }
    }
    else
    {
        //otherwise, we display the values of the database
        $dnn = mysql_fetch_array(mysql_query('select username,password,email,avatar from users where username="'.$_SESSION['username'].'"'));
        $username = htmlentities($dnn['username'], ENT_QUOTES, 'UTF-8');
        $password = htmlentities($dnn['password'], ENT_QUOTES, 'UTF-8');
        $email = htmlentities($dnn['email'], ENT_QUOTES, 'UTF-8');
        $avatar = htmlentities($dnn['avatar'], ENT_QUOTES, 'UTF-8');
    }
    //We display the form
?>


<div class="content">
<?php include('adverts.php'); ?>
<br />
<form action="edit_infos.php" method="post" class="message">
    <i><b>Edit your personal Info</b></i><br />
    <div class="center">
        <label for="username">Username</label><input type="text" name="username" id="username" value="<?php echo $username; ?>" /><br />
        <label for="password">Password<span class="small">(6 characters min.)</span></label><input type="password" name="password" id="password" value="<?php echo $password; ?>" /><br />
        <label for="passverif">Password<span class="small">(verification)</span></label><input type="password" name="passverif" id="passverif" value="<?php echo $password; ?>" /><br />
        <label for="email">Email</label><input type="text" name="email" id="email" value="<?php echo $email; ?>" /><br />
        <label for="avatar">Avatar<span class="small">(optional)</span></label>
        <input name="avatar" type="file" id="avatar" size="50" value="<?php echo $avatar; ?>" />
        <br />
        <input type="submit" value="Send" />
    </div>
</form>
</div>
<?php
}
}
else
 {
?>
<div class="message">You must be a registered member to access this Page.<br />
<a href="connexion.php">Log in</a></div>
<?php
}
?>

发布表单的代码、表单指向的页面代码、保存图片的文件夹、图片的重命名方式以及有关要保存新图像名称的db表的信息。还请记住,您必须修改视图,以便在评论框可以包含我的脚本的地方显示上载的个人资料图片编辑您的问题,在那里添加代码;将其隔开4个单位,以便突出显示为代码。好的,谢谢,我已经完成了,所以我等待您的帮助。如果您注册,让人们立即使用他们的个人资料是没有意义的。一个人想要快速注册。我真的希望你把这个配置文件pic设置为可选的:)如果你正在学习PHP,那么使用
pdo
/
mysqli
函数,而不是旧的去擦亮的
mysql
函数会更明智。你跳过老路,走捷径;)