-4
// Check his status.
if (!empty($_SESSION[username]))
{
echo "Hi, <b>$_SESSION[username]</b>.";

if ($_POST['submit'])
{

    //get file attributes
    $name = $_FILES['myfile']['name'];
    $tmp_name = $_FILES['myfile']['tmp_name'];

if ($name)
{
    //start upload process

    $location = "avatars/$name";
    move_uploaded_file($tmp_name,$location);

        $query = mysql_query("UPDATE members SET imagelocation='$location' WHERE username='$username'");

        die("Your image has been uploaded! <a href='dashboard.php'>Back</a>");


}
else
die("Please select file");
}
echo "upload your image:

<form action='profile.php' method='POST' enctype='multipart/formdata'>

File: <input type='file' name='myfile'> <input type='submit' name='Submit' value='Upload'></form>";

}

它显示用户名很好,我在数据库中有正确的表和列但是当你点击上传时它什么都不做?

您可以通过以用户名登录自己查看:test 密码:test url:learning.iamdanbarrett.com

4

3 回答 3

1

我认为您的查询有问题

$query = mysql_query("UPDATE members SET imagelocation='$location' WHERE username='$username'");

因为您没有在脚本中的任何位置定义 $username 变量,因此您的查询正在检查

UPDATE members SET imagelocation='$location' WHERE username ='';
于 2013-04-20T09:58:22.360 回答
0

if ($_POST['submit'])应该是if ($_POST['Submit'])因为您的提交按钮名称以大写S开头而不是小 s

于 2013-04-20T10:01:52.113 回答
0

代替

if ($_POST['submit'])

if (isset($_POST['submit']))
于 2013-04-20T10:33:55.277 回答