Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

$_POST returns only last value from an array 1

Status
Not open for further replies.

DaSe

Programmer
Feb 14, 2008
149
GB
Hello guys...

If I may ask you for help regarding checkboxes values..The boxes are names into array but $_POST returns only the last value. Here's the code:

Code:
in a while loop:
$mem_dir_add_pic .= "<a href='see_member.php?id=$user_id'><img src='members/avatar/avatar.jpg' width='41' height='60' border='1'  align='left' hspace='3' vspace='5' style='border-color:black' alt='' title='' style='float:left'/><span class='style2' style='float:left;margin-top:55px;margin-left:-46px'>&nbsp;".$user."&nbsp;</span></a>";

$mem_dir_add_pic .= "<form method='post' name='myform' id='myform' action='remove_members.php'><span style='float:left;margin-top:2px;margin-left:-5px'><input type='checkbox' name='del_mem[]' value='".$user_id."'/></span></form>";

}



$mem_check  = $_POST['del_mem'];

if (($mem_check == $user_id) || ($mem_check2 == $user_id))  { 

$proceed = mysql_query("DELETE FROM `members` WHERE friend_id='$mem_check' OR friend_id='$mem_check2' AND user_id='$uid' ");


}


The thing that checkboxes values or title returns correct user_id . But $_POST returns only the last array id of the last inserted picture to be deleted. Thank you for any help.

 
$_POST['del_mem'] will always be an array.
you must address its values in the normal way, by addressing the keys

Code:
foreach ($_POST['del_mem'] as $key=>$value):
 //do something
endforeach;
 
Thank you for your lovely response - however it seems it still doesn't work correctly...

Here what I've done to test it:

Code:
foreach ($_POST['del_mem'] as $key=>$value):
print $value;
endforeach;

..and only the first value of the latest pic is returned. The other pics reply with error:

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\tests\remove_members.php on line 115

I also used this code:

Code:
while (list($key,$val) = @each ($mem_check)) { 
echo "$val";

}

And still only the first value is returned and the rest of the pics return 0.

 
please run the page in a browser and paste the resultant html into the forum.

then paste the results of a print_r($_POST['del_mem']); into the forum too.

please note that only checked checkboxes are ever submitted by a browser. if the box is unchecked it is not submitted.
 
Yes. It only submits when the checkbox is checked of course. There are 3 pics in the table next to each other with their ids - 234 , 232 ,243. When you tick the first pic's checkbox - the result on the page says:

234 - which is the first id and it's correct. When you press the second or third checkbox - nothing happens. No output on the page at all. Or the result says 0 - on foreach code. So it doesn;t matter how many pics are in the table I can only delete the recent one which was inserted in "added members" page. Those pics show in exactly the same order on "remove_members" and only the first on the left always returns anything. It seems like name='del_mem[]' doesn't store anything as an array but when you put title into checkboxes - they show correct ids upon mouseover. It's strange. Here's the all code from "remove_users.php":

Code:
<?php
session_start();
require("connections/conn.php");

$sql = mysql_query("SELECT * FROM `auth` WHERE `userName`='".$_SESSION['logged']."'");
while ($rows = mysql_fetch_array($sql)) {
$userId = $rows['uid'];
$_SESSION['id'] = $userId;
}

//id check
$id = $_SESSION['id'];
$number  = rand(1,10000);
$fileDir = "members/$id/";
$picName = "userImg1.jpg";

//pic check
$new_pic = "members/$id/userImg1.jpg";



if (($_FILES['uploadPic']['tmp_name']=="") && ($_POST['submitPic'])) {
$errorPic = "&nbsp;! Picture not chosen&nbsp;";
} 

  else if ($_FILES['uploadPic']['size'] > 512000) { $errorPic = "&nbsp;! File is too large&nbsp;"; 
   unlink ($_FILES['uploadPic']['tmp_name']); 
    }
  else if ((!preg_match("/\.(gif|jpg|jpeg|png)$/i", $_FILES['uploadPic']['name'])) && ($_FILES['uploadPic']['name']!=""))  { $errorPic = "&nbsp;Wrong file type..&nbsp;"; }
  
 
  
else if(is_uploaded_file($_FILES['uploadPic']['tmp_name'])) { 

move_uploaded_file($_FILES['uploadPic']['tmp_name'],"$fileDir".$picName);
$errorPic = "&nbsp;Picture updated&nbsp;"; 


}
?>
<?php

//members add
$sql_members = mysql_query("SELECT * FROM `auth` WHERE `userName`='".$_SESSION['logged']."'");

while ( $row = mysql_fetch_array($sql_members)) { 
$userName = $row['userName'];
$uid = $row['uid'];
}

$sql_members_name = mysql_query("SELECT a.userName, a.uid, m.uid, m.friend_id , m.user_id FROM `auth` a LEFT OUTER JOIN `members` m ON a.uid = m.friend_id ");




$sql_members_add = mysql_query("SELECT * FROM `members`,`auth` WHERE auth.uid=members.friend_id AND members.user_id = '$uid' ORDER BY `user_id` DESC");

while ($rows = mysql_fetch_array($sql_members_add)) { 
$friends = $rows['friend_id'];
$user = $rows['userName'];
$user_id = $rows['friend_id'];

//name length
$user = substr($user, 0, 12);

//$strFirstname = strlen($user);
//if ($strFirstname>5) { $user.=".."; }
/////////////



$f_ex = "members/".$friends."/userImg1.jpg";
if (file_exists($f_ex)) {
$mem_dir_add_pic .= "<form method='post' name='myform' id='myform' action='remove_members.php'><a href='see_member.php?id=$user_id'><img src='members/".$friends."/userImg1.jpg' width='41' height='60' border='1'  align='left' hspace='3' vspace='5' style='border-color:black' alt='' title='' style='float:left'/><span class='style2' style='float:left;margin-top:55px;margin-left:-46px'>&nbsp;".$user."&nbsp;</span></a><span style='float:left;margin-top:2px;margin-left:-5px'><input type='checkbox' name='del_mem2' value='".$user_id."' /></span></form>";
} else { 

$mem_dir_add_pic .= "<a href='see_member.php?id=$user_id'><img src='members/avatar/avatar.jpg' width='41' height='60' border='1'  align='left' hspace='3' vspace='5' style='border-color:black' alt='' title='' style='float:left'/><span class='style2' style='float:left;margin-top:55px;margin-left:-46px'>&nbsp;".$user."&nbsp;</span></a>";




}
//$array_pic[] .= "<img src='$mem_dir_add' width='40' height='60' border='1' align='left'/>";
$mem_dir_add_pic .= "<form method='post' name='myform' id='myform' action='remove_members.php'><span style='float:left;margin-top:2px;margin-left:-5px'><input type='checkbox' name='del_mem[$user_id][]' title='$user_id' value='".$user_id."'/></span></form>";
}

//remove members
$sel_rem = mysql_query("SELECT * FROM `members`");
while ($row_ = mysql_fetch_array($sel_rem)) { 
//$one = array($mem_dir_add_pic); 
$id_fr = $row_['friend_id'];

}

//print_r ($one);


//$_POST['del_mem'];


$mem_check  = $_REQUEST['del_mem'];
$one = array($mem_check);
//array_push($one,$_POST['del_mem']);
$mem_check2 = $_POST['del_mem2'];
//$one = array($mem_dir_add_pic);

//print $mem_check;
/*
while (list($key,$val) = @each ($mem_check)) { 
echo "$val";

}

*/
foreach ($_POST['del_mem'] as $key=>$value):
print $key;
endforeach;
//print $mem_check;
if (($mem_check == $user_id) || ($mem_check2 == $user_id))  { 

$proceed = mysql_query("DELETE FROM `members` WHERE friend_id='$mem_check' OR friend_id='$mem_check2' AND user_id='$uid' ");


}
?>
<?php
//public profile

$sql_public4 = mysql_query("SELECT * FROM `auth` WHERE `mailActive`='1' AND `userName`='".$_SESSION['logged']."'");

while ($row_pub4 = mysql_fetch_array($sql_public4)) { 

$id_pub4 = $row_pub4['uid'];

}


?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="shortcut icon" href="images/fav.ico" type="image/x-icon" />
<title>Musicooler</title>
<style type="text/css">

A.imgbord:link {color: #000000;}
A.imgbord:active {color: #000000;}
A.imgbord:visited {color: #000000;}
A.imgbord:hover {color: #000000;}



body {
	background-image: url(images/backGroundMain.jpg);
	background-repeat: repeat-y;
	background-position:center;
	position:relative;
	margin-top: 0px;
	margin-left: 0px;
	background-attachment:fixed;
	
	
}


#picForm { 
  width: 220px;
  height: 24px; 
  margin: 0px;
  padding: 0px;
  vertical-align: middle;
  /*background-image: url(images/backGroundMain.jpg);*/
  background-color: #333333;
  color: #ffffff;
  border-color:#000000;   
}

#favMusicId {

background-color: #333444;
color:#ffffff;
border-color:#000000; 

}


#submitPic { 
  height:24px; 
  width: 29px;
  margin: 0px;
  padding: 0px;
  border: 1px;
  background-color: #000000;
  color:#FFFFFF;
  vertical-align:bottom;
  
}

#submitPicArea1 { 

  height:24px; 
  width: 29px;
  margin: 0px;
  padding: 0px;
  border: 1px;
  background-color: #000000;
  color:#FFFFFF;
  vertical-align:bottom;
  
 }
 
 #submitPicArea2 { 

  height:24px; 
  width: 29px;
  margin: 0px;
  padding: 0px;
  border: 1px;
  background-color: #000000;
  color:#FFFFFF;
  vertical-align:bottom;
  margin-left:213px;
  margin-top:5px;
  
 }
 
 #radioSub { 
 
   height:24px; 
  width: 29px;
  margin: 0px;
  padding: 0px;
  border: 1px;
  background-color: #000000;
  color:#FFFFFF;
  }

#sayForm {

  height:100px; 
  width: 200px;
  margin: 1px;
  padding:0px;
  background-attachment: fixed;
  background-image: url(images/backGroundMain.jpg);
  resize:none;
  border:thin;
  display:inline;
  font-family: Arial, Helvetica, sans-serif;
  font-size:12px;
  color:#FFFFFF;
  font-weight:400;
  vertical-align: text-top;
  overflow:hidden;
  margin-left:23px;
  
  
   }
   
#table {

table-layout: fixed;
overflow: hidden;


}
   
#personalForm {

margin-top:32px;
margin-left:-20px;

}
  

.style1 {font-family: Verdana, Arial, Helvetica, sans-serif;}


.style2 {
	font-size: 9px;
	color: #FFFFFF;
	font-family: Arial, Helvetica, sans-serif;
	background-color: #003333;
	
}
style1 {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 9px;
	background-color: #666666;
	color: #FFFFFF;
}
a:link {
	text-decoration: none;
	color: #FFFFFF;
	
}
a:visited {
	text-decoration: none;
	color: #FFFFFF;
}
a:hover {
	text-decoration: none;
	color: #FFFFFF;
}
a:active {
	text-decoration: none;
	color: #FFFFFF;
}
#apDiv1 {
	position:absolute;
	left:183px;
	top:16px;
	width:65px;
	height:55px;
	z-index:1;
}
.style3 {
	color: #FFFFFF;
	font-family: Arial, Helvetica, sans-serif;
	font-size: 9px;
	padding: 0px;
	margin-top: -20px;
	clip: rect(0px,auto,auto,auto);
	position: relative;
	background-color: #B92F00;
}
.style4 {
	font-size: 10px;
	color: #FFFFFF;
	margin-top:0px;
	padding: 0px;
	position: static;
	left: auto;
	z-index: 1;
	float: none;
	width: auto;
	clip: rect(30px,auto,auto,780px);
	font-family: Arial, Helvetica, sans-serif;
}



</style>
<script src="../Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
</head>

<body>
<div class="chooseBar">
  <div align="center">
    <p align="center"><span class="style1"> <br />
        <br />
      <script type="text/javascript">
AC_FL_RunContent( 'codebase','[URL unfurl="true"]http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','546','height','120','src','flash/chooseBar','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','wmode','transparent','loop','false','play','false','movie','flash/chooseBar'[/URL] ); //end AC code
</script><noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="[URL unfurl="true"]http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0"[/URL] width="546" height="120">
          <param name="movie" value="flash/chooseBar.swf" />
          <param name="quality" value="high" />
          <param name="wmode" value="transparent" /><param name="LOOP" value="false" /><param name="PLAY" value="false" />
          <embed height="120" width="546" src="flash/chooseBar.swf" type="application/x-shockwave-flash" quality="high" pluginspage="[URL unfurl="true"]http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash"[/URL] wmode="transparent" loop="false" play="false"></embed>
        </object>
</noscript>
      <br />
</span></p>
    <p align="center"><strong><span class="style4">
      <?php if (!$_SESSION['logged']) { print"<a href='login.php'><u>Login</u></a>";} else { print"<a href='see_member.php?id=$id_pub4'><u>Public profile</u></a>&nbsp;&bull;&nbsp;<a href='login.php'><u>Log</u> <u>out</u></a>";} ?>
      &bull;&nbsp;<a href="index.php"><u>Home</u></a>&nbsp;&bull;&nbsp;<a href="profile_edit.php"><u>Back</u></a></span></strong><span class="style4">&nbsp;
      <?php if ($_SESSION['logged']){ print"<b>&bull; <i>Logged as:</i>&nbsp;</b>";}?>
      </span> <span class="style3"><?php print $_SESSION['logged']; ?><br />
    </span><br />
    <br/><br/><span class="style3"><?php if ($_SESSION['logged']) { print"&nbsp;Your profile update&nbsp;"; } ?></span></p>
    <div><?php if ($_SESSION['logged']) { if (file_exists($new_pic)) { print"<img src='members/$id/userImg1.jpg?$number' width='60' height='80' border='1'/>"; }  else { print"<img src='members/avatar/avatar.jpg' width='60' height='80' border='1'/>"; }} ?></div><br/>
    <div></div>
    <p align="center"><span class="style3"><?php print $errorPic; ?></span><br />
      <br />
    <table width="666" height="127" border="1" cellpadding="0" cellspacing="0" bordercolor="#333333" id="table">
      <tr>
      <td width="292" height="21" background="images/backGroundMain.png" bgcolor="#666666">
  
      
        <div align="left"></div>        </td>
<td width="368" bgcolor="#666666"> <div align="center"></div></td>
      </tr>
      <tr>
        <td height="52" background="images/aoftBack.jpeg" bgcolor="#666666"><div align="center"><span class="style2">&nbsp;&bull;&nbsp;EDIT MEMBERS&nbsp&bull;&nbsp;</span>&nbsp;</div></td>
        <td background="images/backGroundMain.png"><?php print $mem_dir_add_pic; ?>&nbsp;</td>
      </tr>
      <tr>
        <td height="52" background="images/aoftBack.jpeg" bgcolor="#666666">&nbsp;</td>
        <td background="images/backGroundMain.png"><img src="images/avatar.jpg" onclick="document.getElementById('myform').submit();"/> 
&nbsp;</td>
      </tr>
      </table> 
    </p>
 </div>
</div>

</body>
</html>

Regards.
 
please just post the rendered html as per my message.
 
Here is more clear PHP code without comments etc.

Code:
<?php
session_start();
require("connections/conn.php");

$sql = mysql_query("SELECT * FROM `auth` WHERE `userName`='".$_SESSION['logged']."'");
while ($rows = mysql_fetch_array($sql)) {
$userId = $rows['uid'];
$_SESSION['id'] = $userId;
}

//id check
$id = $_SESSION['id'];
$number  = rand(1,10000);
$fileDir = "members/$id/";
$picName = "userImg1.jpg";

//pic check
$new_pic = "members/$id/userImg1.jpg";



if (($_FILES['uploadPic']['tmp_name']=="") && ($_POST['submitPic'])) {
$errorPic = "&nbsp;! Picture not chosen&nbsp;";
} 

  else if ($_FILES['uploadPic']['size'] > 512000) { $errorPic = "&nbsp;! File is too large&nbsp;"; 
   unlink ($_FILES['uploadPic']['tmp_name']); 
    }
  else if ((!preg_match("/\.(gif|jpg|jpeg|png)$/i", $_FILES['uploadPic']['name'])) && ($_FILES['uploadPic']['name']!=""))  { $errorPic = "&nbsp;Wrong file type..&nbsp;"; }
  
 
  
else if(is_uploaded_file($_FILES['uploadPic']['tmp_name'])) { 

move_uploaded_file($_FILES['uploadPic']['tmp_name'],"$fileDir".$picName);
$errorPic = "&nbsp;Picture updated&nbsp;"; 


}
?>
<?php

//members add
$sql_members = mysql_query("SELECT * FROM `auth` WHERE `userName`='".$_SESSION['logged']."'");

while ( $row = mysql_fetch_array($sql_members)) { 
$userName = $row['userName'];
$uid = $row['uid'];
}

$sql_members_name = mysql_query("SELECT a.userName, a.uid, m.uid, m.friend_id , m.user_id FROM `auth` a LEFT OUTER JOIN `members` m ON a.uid = m.friend_id ");




$sql_members_add = mysql_query("SELECT * FROM `members`,`auth` WHERE auth.uid=members.friend_id AND members.user_id = '$uid' ORDER BY `user_id` DESC");

while ($rows = mysql_fetch_array($sql_members_add)) { 
$friends = $rows['friend_id'];
$user = $rows['userName'];
$user_id = $rows['friend_id'];

//name length
$user = substr($user, 0, 12);

//$strFirstname = strlen($user);
//if ($strFirstname>5) { $user.=".."; }
/////////////



$f_ex = "members/".$friends."/userImg1.jpg";
if (file_exists($f_ex)) {
$mem_dir_add_pic .= "<form method='post' name='myform' id='myform' action='remove_members.php'><a href='see_member.php?id=$user_id'><img src='members/".$friends."/userImg1.jpg' width='41' height='60' border='1'  align='left' hspace='3' vspace='5' style='border-color:black' alt='' title='' style='float:left'/><span class='style2' style='float:left;margin-top:55px;margin-left:-46px'>&nbsp;".$user."&nbsp;</span></a><span style='float:left;margin-top:2px;margin-left:-5px'><input type='checkbox' name='del_mem2' value='".$user_id."' /></span></form>";
} else { 

$mem_dir_add_pic .= "<a href='see_member.php?id=$user_id'><img src='members/avatar/avatar.jpg' width='41' height='60' border='1'  align='left' hspace='3' vspace='5' style='border-color:black' alt='' title='' style='float:left'/><span class='style2' style='float:left;margin-top:55px;margin-left:-46px'>&nbsp;".$user."&nbsp;</span></a>";




}

$mem_dir_add_pic .= "<form method='post' name='myform' id='myform' action='remove_members.php'><span style='float:left;margin-top:2px;margin-left:-5px'><input type='checkbox' name='del_mem[$user_id][]' title='$user_id' value='".$user_id."'/></span></form>";

}



$mem_check  = $_POST['del_mem'];
$mem_check2 = $_POST['del_mem2'];





if (($mem_check == $user_id) || ($mem_check2 == $user_id))  { 

$proceed = mysql_query("DELETE FROM `members` WHERE friend_id='$mem_check' OR friend_id='$mem_check2' AND user_id='$uid' ");


}


?>

 
please just post the rendered html as per my message.
 
Jpadie - the page is not on the server yet - the site is being worked on locally. What exactly do you mean by saying rendered page ? ( Sorry if it sounds silly ).

 
Here's the direct link for the screenshot:


And source code:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="shortcut icon" href="images/fav.ico" type="image/x-icon" />
<title>Musicooler</title>
<style type="text/css">

A.imgbord:link {color: #000000;}
A.imgbord:active {color: #000000;}
A.imgbord:visited {color: #000000;}
A.imgbord:hover {color: #000000;}



body {
	background-image: url(images/backGroundMain.jpg);
	background-repeat: repeat-y;
	background-position:center;
	position:relative;
	margin-top: 0px;
	margin-left: 0px;
	background-attachment:fixed;
	
	
}


#picForm { 
  width: 220px;
  height: 24px; 
  margin: 0px;
  padding: 0px;
  vertical-align: middle;
  /*background-image: url(images/backGroundMain.jpg);*/
  background-color: #333333;
  color: #ffffff;
  border-color:#000000;   
}

#favMusicId {

background-color: #333444;
color:#ffffff;
border-color:#000000; 

}


#submitPic { 
  height:24px; 
  width: 29px;
  margin: 0px;
  padding: 0px;
  border: 1px;
  background-color: #000000;
  color:#FFFFFF;
  vertical-align:bottom;
  
}

#submitPicArea1 { 

  height:24px; 
  width: 29px;
  margin: 0px;
  padding: 0px;
  border: 1px;
  background-color: #000000;
  color:#FFFFFF;
  vertical-align:bottom;
  
 }
 
 #submitPicArea2 { 

  height:24px; 
  width: 29px;
  margin: 0px;
  padding: 0px;
  border: 1px;
  background-color: #000000;
  color:#FFFFFF;
  vertical-align:bottom;
  margin-left:213px;
  margin-top:5px;
  
 }
 
 #radioSub { 
 
   height:24px; 
  width: 29px;
  margin: 0px;
  padding: 0px;
  border: 1px;
  background-color: #000000;
  color:#FFFFFF;
  }

#sayForm {

  height:100px; 
  width: 200px;
  margin: 1px;
  padding:0px;
  background-attachment: fixed;
  background-image: url(images/backGroundMain.jpg);
  resize:none;
  border:thin;
  display:inline;
  font-family: Arial, Helvetica, sans-serif;
  font-size:12px;
  color:#FFFFFF;
  font-weight:400;
  vertical-align: text-top;
  overflow:hidden;
  margin-left:23px;
  
  
   }
   
#table {

table-layout: fixed;
overflow: hidden;


}
   
#personalForm {

margin-top:32px;
margin-left:-20px;

}
  

.style1 {font-family: Verdana, Arial, Helvetica, sans-serif;}


.style2 {
	font-size: 9px;
	color: #FFFFFF;
	font-family: Arial, Helvetica, sans-serif;
	background-color: #003333;
	
}
style1 {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 9px;
	background-color: #666666;
	color: #FFFFFF;
}
a:link {
	text-decoration: none;
	color: #FFFFFF;
	
}
a:visited {
	text-decoration: none;
	color: #FFFFFF;
}
a:hover {
	text-decoration: none;
	color: #FFFFFF;
}
a:active {
	text-decoration: none;
	color: #FFFFFF;
}
#apDiv1 {
	position:absolute;
	left:183px;
	top:16px;
	width:65px;
	height:55px;
	z-index:1;
}
.style3 {
	color: #FFFFFF;
	font-family: Arial, Helvetica, sans-serif;
	font-size: 9px;
	padding: 0px;
	margin-top: -20px;
	clip: rect(0px,auto,auto,auto);
	position: relative;
	background-color: #B92F00;
}
.style4 {
	font-size: 10px;
	color: #FFFFFF;
	margin-top:0px;
	padding: 0px;
	position: static;
	left: auto;
	z-index: 1;
	float: none;
	width: auto;
	clip: rect(30px,auto,auto,780px);
	font-family: Arial, Helvetica, sans-serif;
}



</style>
<script src="../Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
</head>

<body>
<div class="chooseBar">
  <div align="center">
    <p align="center"><span class="style1"> <br />
        <br />
      <script type="text/javascript">
AC_FL_RunContent( 'codebase','[URL unfurl="true"]http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','546','height','120','src','flash/chooseBar','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','wmode','transparent','loop','false','play','false','movie','flash/chooseBar'[/URL] ); //end AC code
</script><noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="[URL unfurl="true"]http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0"[/URL] width="546" height="120">
          <param name="movie" value="flash/chooseBar.swf" />
          <param name="quality" value="high" />
          <param name="wmode" value="transparent" /><param name="LOOP" value="false" /><param name="PLAY" value="false" />
          <embed height="120" width="546" src="flash/chooseBar.swf" type="application/x-shockwave-flash" quality="high" pluginspage="[URL unfurl="true"]http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash"[/URL] wmode="transparent" loop="false" play="false"></embed>
        </object>
</noscript>
      <br />
</span></p>
    <p align="center"><strong><span class="style4">
      <a href='see_member.php?id=187'><u>Public profile</u></a>&nbsp;&bull;&nbsp;<a href='login.php'><u>Log</u> <u>out</u></a>      &bull;&nbsp;<a href="index.php"><u>Home</u></a>&nbsp;&bull;&nbsp;<a href="profile_edit.php"><u>Back</u></a></span></strong><span class="style4">&nbsp;
      <b>&bull; <i>Logged as:</i>&nbsp;</b>      </span> <span class="style3">david<br />
    </span><br />
    <br/><br/><span class="style3">&nbsp;Your profile update&nbsp;</span></p>
    <div><img src='members/187/userImg1.jpg?2638' width='60' height='80' border='1'/></div><br/>
    <div></div>
    <p align="center"><span class="style3"></span><br />
      <br />
    <table width="666" height="127" border="1" cellpadding="0" cellspacing="0" bordercolor="#333333" id="table">
      <tr>
      <td width="292" height="21" background="images/backGroundMain.png" bgcolor="#666666">
  
      
        <div align="left"></div>        </td>
<td width="368" bgcolor="#666666"> <div align="center"></div></td>
      </tr>
      <tr>
        <td height="52" background="images/aoftBack.jpeg" bgcolor="#666666"><div align="center"><span class="style2">&nbsp;&bull;&nbsp;EDIT MEMBERS&nbsp&bull;&nbsp;</span>&nbsp;</div></td>
        <td background="images/backGroundMain.png"><a href='see_member.php?id=234'><img src='members/avatar/avatar.jpg' width='41' height='60' border='1'  align='left' hspace='3' vspace='5' style='border-color:black' alt='' title='' style='float:left'/><span class='style2' style='float:left;margin-top:55px;margin-left:-46px'>&nbsp;daveTwo&nbsp;</span></a><form method='post' name='myform' id='myform' action='remove_members.php'><span style='float:left;margin-top:2px;margin-left:-5px'><input type='checkbox' name='del_mem[]' title='234' value='234'/></span></form><a href='see_member.php?id=232'><img src='members/avatar/avatar.jpg' width='41' height='60' border='1'  align='left' hspace='3' vspace='5' style='border-color:black' alt='' title='' style='float:left'/><span class='style2' style='float:left;margin-top:55px;margin-left:-46px'>&nbsp;shoe&nbsp;</span></a><form method='post' name='myform' id='myform' action='remove_members.php'><span style='float:left;margin-top:2px;margin-left:-5px'><input type='checkbox' name='del_mem[]' title='232' value='232'/></span></form><a href='see_member.php?id=243'><img src='members/avatar/avatar.jpg' width='41' height='60' border='1'  align='left' hspace='3' vspace='5' style='border-color:black' alt='' title='' style='float:left'/><span class='style2' style='float:left;margin-top:55px;margin-left:-46px'>&nbsp;daveTen&nbsp;</span></a><form method='post' name='myform' id='myform' action='remove_members.php'><span style='float:left;margin-top:2px;margin-left:-5px'><input type='checkbox' name='del_mem[]' title='243' value='243'/></span></form>&nbsp;</td>
      </tr>
      <tr>
        <td height="52" background="images/aoftBack.jpeg" bgcolor="#666666">&nbsp;</td>
        <td background="images/backGroundMain.png"><img src="images/aotw.jpg" onclick="document.getElementById('myform').submit();"/> 
&nbsp;</td>
      </tr>
      </table> 
    </p>
 </div>
</div>

</body>
</html>
 
The name='del_mem[]' just doesn't store the array...No matter how much I would like it to do so.The title inside the checkbox tag though, returns correct id from any checkbox that is placed next to each pic...

 
I am positive now that name='del_mem[]' doesn't store array. I've used is_array function and it returned error:" Variable passed to each() is not an array ". So in other words the array function from checkboxes doesn't work when checkboxes are inserted within PHP. There must be a workaround I guess..

 
look at this rendered html
Code:
<td background="images/backGroundMain.png">
                                <a href='see_member.php?id=234'><img src='members/avatar/avatar.jpg' width='41' height='60' border='1' align='left' hspace='3' vspace='5' style='border-color:black' alt='' title='' style='float:left'/><span class='style2' style='float:left;margin-top:55px;margin-left:-46px'>&nbsp;daveTwo&nbsp;</span></a>
                                <form method='post' name='myform' id='myform' action='remove_members.php'>
                                    <span style='float:left;margin-top:2px;margin-left:-5px'><input type='checkbox' name='del_mem[]' title='234' value='234'/></span>
                                </form><a href='see_member.php?id=232'><img src='members/avatar/avatar.jpg' width='41' height='60' border='1' align='left' hspace='3' vspace='5' style='border-color:black' alt='' title='' style='float:left'/><span class='style2' style='float:left;margin-top:55px;margin-left:-46px'>&nbsp;shoe&nbsp;</span></a>
                                <form method='post' name='myform' id='myform' action='remove_members.php'>
                                    <span style='float:left;margin-top:2px;margin-left:-5px'><input type='checkbox' name='del_mem[]' title='232' value='232'/></span>
                                </form><a href='see_member.php?id=243'><img src='members/avatar/avatar.jpg' width='41' height='60' border='1' align='left' hspace='3' vspace='5' style='border-color:black' alt='' title='' style='float:left'/><span class='style2' style='float:left;margin-top:55px;margin-left:-46px'>&nbsp;daveTen&nbsp;</span></a>
                                <form method='post' name='myform' id='myform' action='remove_members.php'>
                                    <span style='float:left;margin-top:2px;margin-left:-5px'><input type='checkbox' name='del_mem[]' title='243' value='243'/></span>
                                </form>&nbsp;
                            </td>

you can see that each input is within its own form tag. that means that only one will ever get submitted.
you need to read up on basic html and forms processing. only one form is ever submitted per event (page refresh). only the controls in that form are submitted. to be 'in the form', the control must be between the <form> tags.

I suspect that this is the output that you really want
Code:
    <td background="images/backGroundMain.png">
                                <a href='see_member.php?id=234'><img src='members/avatar/avatar.jpg' width='41' height='60' border='1' align='left' hspace='3' vspace='5' style='border-color:black' alt='' title='' style='float:left'/><span class='style2' style='float:left;margin-top:55px;margin-left:-46px'>&nbsp;daveTwo&nbsp;</span></a>
                                <form method='post' name='myform' id='myform' action='remove_members.php'>
                                    <span style='float:left;margin-top:2px;margin-left:-5px'><input type='checkbox' name='del_mem[]' title='234' value='234'/></span>
                                <a href='see_member.php?id=232'><img src='members/avatar/avatar.jpg' width='41' height='60' border='1' align='left' hspace='3' vspace='5' style='border-color:black' alt='' title='' style='float:left'/><span class='style2' style='float:left;margin-top:55px;margin-left:-46px'>&nbsp;shoe&nbsp;</span></a>
                                    <span style='float:left;margin-top:2px;margin-left:-5px'><input type='checkbox' name='del_mem[]' title='232' value='232'/></span>
                                <a href='see_member.php?id=243'><img src='members/avatar/avatar.jpg' width='41' height='60' border='1' align='left' hspace='3' vspace='5' style='border-color:black' alt='' title='' style='float:left'/><span class='style2' style='float:left;margin-top:55px;margin-left:-46px'>&nbsp;daveTen&nbsp;</span></a>
                                    <span style='float:left;margin-top:2px;margin-left:-5px'><input type='checkbox' name='del_mem[]' title='243' value='243'/></span>
                                </form>&nbsp;
                            </td>

separately I counsel getting rid of all those inline styles. they make the source code very hard to read, and very time-consuming to change
 
Thank you so much. I'll take a look into it in a moment. That explains why I couldn't store it into array. The thing is you've just made each form tag to each user id - but how did you know that these users always be in a table and will get deleted ? I passed you random ids.The members are the ones which added by the users and the user decides which ones to delete later.

 
I know the basic of forms - I placed as you told the boxes one by one wrapped with a form tag. And still the same thing only one output. The thing is this: NO matter how many checkboxes there will be in one form the array only outputs first ( recent ) value. This the proof when I placed this code:

Code:
echo '<pre>', print_r($_POST, true), '</pre>';

...and the output is this:

Array
(
)

..and when you tick the box of the most recent user/pic the array returns properly but only latest value:

Array
(
[del_mem] => Array
(
[0] => 242
)

)


The question is pretty hard to solve. I realise that. I placed this on a few fora. What I'm trying to do is this:

There will be only one checkbox which is concatenated. The name of the checkbox must be a dynamically changing string ,something like that:

Code:
$mem_dir_add_pic .="<form method='post' name='myform' id='myform' action='remove_members.php'><a href='see_member.php?id=$user_id'><img src='members/avatar/avatar.jpg'><input type='checkbox' name='del_mem:$user_id' title='de:[$user_id]' value='$user_id'/></span>

..and then you would use explode to retrieve $user_id from the string in the checkbox name. But I don't know yet how to fetch string from a name.

Regards.
</form>";

 
I would like to thank for you replies. Have changed strategy of the removing page and no longer will spend time on this one. I don't think checkboxes can be concatenated within PHP and dynamically return name strings. Regards.

 
the correct method is via an array, as I showed you.

Code:
<?php if (!empty($_POST)) print_r($_POST); ?>
<form method="post">
<input type="checkbox" name="test[]" value="1" />test 1<br/>
<input type="checkbox" name="test[]" value="2" />test 2<br/>
<input type="checkbox" name="test[]" value="3" />test 3<br/>
<input type="checkbox" name="test[]" value="4"/>test 4<br/>
<input type="submit" />
</form>
clicking all four checkboxes gives this
Code:
Array ( [test] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 ) )
which is exactly as anticipated.
clicking on the last two gives this
Code:
Array ( [test] => Array ( [0] => 3 [1] => 4 ) )
again, exactly as anticipated
clicking on just the last gives this
Code:
Array ( [test] => Array ( [0] => 4 ) )

as you could tell from my earlier post on this topic in the other thread, I prefer to rely on the key rather than the value for identifying a checkbox

Code:
[code]
<?php if (!empty($_POST)) print_r($_POST); ?>
<form method="post">
<input type="checkbox" name="test[1]" value="on" />test 1<br/>
<input type="checkbox" name="test[2]" value="on" />test 2<br/>
<input type="checkbox" name="test[3]" value="on" />test 3<br/>
<input type="checkbox" name="test[4]" value="on"/>test 4<br/>
<input type="submit" />
</form>

and checking each box would then return
Code:
Array ( [test] => Array ( [1] => on [2] => on [3] => on [4] => on ) )

then it is just a case of iterating the results

Code:
<?php 
if (!empty($_POST)):
	foreach ($_POST['test'] as $value=>$duff):
		echo "checkbox $value was checked <br/>";
	endforeach;
endif;
?>
<form method="post">
<input type="checkbox" name="test[1]" value="on" />test 1<br/>
<input type="checkbox" name="test[2]" value="on" />test 2<br/>
<input type="checkbox" name="test[3]" value="on" />test 3<br/>
<input type="checkbox" name="test[4]" value="on"/>test 4<br/>
<input type="submit" />
</form>
and in this case checking all the boxes save the third gives this result

Code:
checkbox 1 was checked 
checkbox 2 was checked 
checkbox 4 was checked
 
Thanks Jpadie for the extra explanation. I can see clearly now how it should work. BUT - ALL THE PROBLEM and the gist of it is the you CAN'T WRITE NUMBER OF BOXES beacuse you don't know it - the checkbox(es) need to appear next to the corresposnding user from the table. If I have added 3 members and later want them to be deleted ? And other user has 1 member to delete ? Can you get me ? Now I have zero users in my table to delete - so the checkboxes need to vanish. Sorry for such a rudimentary explanation - but the checkboxes need to appear in the same number as the number of the users in the table. Is it something I don't understand ? Regards.

 
P.S. So in order for the boxes to appear as many times as users' pics the boxes need to be concatenated ( I guess ) - and this is where the problem lies - if you concatenate them - they won't return an array ! ( At least I don't know how to do this now ). If I had always the same number of users to delete that would be no problem and your solution would be used like no one's else....

I hope we understand each other..Regards.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top