// 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 password:test url:learning.iamdanbarrett.com
答案 0 :(得分:1)
我认为您的查询存在问题
$query = mysql_query("UPDATE members SET imagelocation='$location' WHERE username='$username'");
因为您没有在脚本中的任何位置定义$ username变量,因此您的查询正在检查
UPDATE members SET imagelocation='$location' WHERE username ='';
答案 1 :(得分:0)
if($ _POST ['submit'])应 if($ _POST ['Submit']),因为您的提交按钮名称以大写开头S 而不是小s
答案 2 :(得分:0)
替换
if ($_POST['submit'])
与
if (isset($_POST['submit']))