如何设置个人资料图片

时间:2015-11-21 04:45:15

标签: php html

如果我点击设置的配置文件pic意味着,我想在配置文件pic上设置该图像,我已经设置了该图像值,我必须存储1个剩余值,我必须存储0,在我的代码中它将插入仅限0

$sql=mysql_query("SELECT id FROM useralbum WHERE isprofilepic IN ('1') AND ssmid='$ssmid'");
$count = mysql_num_rows($sql);
if($count == '1'){
 while($row=mysql_fetch_assoc($sql)){
   $profileid = $row['id'];
 }
 $profile=mysql_query("UPDATE useralbum SET isprofilepic='0' WHERE id='$profileid'");
 if($profile){
     echo "SUCCESS";
 }
 else{
    echo "ERROR".mysql_error(); 
 } 
}  

else{    
 $newprofile=mysql_query("UPDATE useralbum SET isprofilepic='1' WHERE isprofilepic='".$_SESSION['profile']."'");
  if($newprofile){
     echo "SUCCESS";
 }
 else{
    echo "ERROR".mysql_error(); 
 } 
} 

1 个答案:

答案 0 :(得分:0)

这是您的情况问题。如果有以前的个人资料照片 。然后它会进入这个区块。它永远不会进入其他部分所以永远不会为新的个人资料照片设置1。

if($count == '1'){
 while($row=mysql_fetch_assoc($sql)){
   $profileid = $row['id'];
 }
 $profile=mysql_query("UPDATE useralbum SET isprofilepic='0' WHERE id='$profileid'");
 if($profile){
     echo "SUCCESS";
 }
 else{
    echo "ERROR".mysql_error(); 
 } 
} 

在此更新上一条记录后,您不会更改新的个人资料照片记录。如果在之前没有设置了配置文件pic,那么它可以工作。它将进入另一部分。但是如果已经设置了配置文件图片并且您更改了它。所以改变你的状况。

$sql=mysql_query("SELECT id FROM useralbum WHERE isprofilepic="1" AND ssmid='$ssmid'");
$count = mysql_num_rows($sql);

//If there is already profile pic set then if block executes and set it to 0.
if($count == '1'){
 while($row=mysql_fetch_assoc($sql)){
   $profileid = $row['id'];
 }
 $profile=mysql_query("UPDATE useralbum SET isprofilepic='0' WHERE id='$profileid'");
 if($profile){
     echo "SUCCESS";
 }
 else{
    echo "ERROR".mysql_error(); 
 } 
}  

   //After setting previous pic 0, update new pic to 1. (This will works on both cases if already profile pic is set and there is first time setting profile pic )
 $newprofile=mysql_query("UPDATE useralbum SET isprofilepic='1' WHERE ssmid='$ssmid'");
  if($newprofile){
     echo "SUCCESS";
 }
 else{
    echo "ERROR".mysql_error(); 
 } 

会给你准确的记录。试试这个。

相关问题