-2
//setting veriables
$imagestring = $_FILES["file"]["name"];
$myuser = $_POST['myusername'];

//mysql set up error handle
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");


$chkuserid = mysql_query("select UserID from users where Username = '".$myuser."'"); 
$row = mysql_fetch_array($chkuserid); 
$finall = $row['UserID']; 
  // putting data into database
var_dump($finall);
$sql="UPDATE users SET avatarstring='k00138899.atspace.eu/photoalbum/upload/".$imagestring."' WHERE UserID='".$finall."'";

我想我尝试了用户表中的所有内容,我有头像字符串,如果上传成功,它将存储图像的路径

userid - int(25)
$finall - string
avatarstring - TEXT
文件被上传,但是图像地址的条目应该和这个操作一起进入 avatarstring 列。


上传图片的代码有效,如果上传成功,此代码将放置在 if 语句中,此代码与图片上传成功的消息一起显示

    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "avatar/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "avatar/" . $_FILES["file"]["name"];

        // if upload successful add entry into DB
$host="fdb4.atspace.com:3306"; // Host name
$username="1259829_photo"; // Mysql username
$password="j8"; // Mysql password
$db_name="1259829_photo"; // Database name
$tbl_name="users"; // Table name

//setting veriables
$imagestring = $_FILES["file"]["name"];
$myuser = $_POST['myusername'];

//mysql set up error handle
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");


$chkuserid = mysql_query("select UserID from users where Username = '".$myuser."'"); 
$row = mysql_fetch_array($chkuserid); 
$finall = $row['UserID']; 
  // putting data into database
var_dump($finall);
var_dump($myuser);

$sql="UPDATE users SET avatarstring='k00138899.atspace.eu/photoalbum/upload/".$imagestring."' WHERE Username='".$myuser."'";


      }
    }
  }
else
  {
  echo "Invalid file";
  }
?> 
4

1 回答 1

0

呵呵,你根本就是不叫到mysql_query( $sql);最后……

否则它看起来很好。将鼠标悬停在您应该考虑使用mysqli_orPDO代替 deprecatedmysql_并确保您的代码不易受到 SQL 注入攻击。

于 2013-04-15T16:17:13.447 回答