Checked boxes, something I'm missing

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Red Blaze
Forum Commoner
Posts: 40
Joined: Mon Mar 27, 2006 3:45 pm

Checked boxes, something I'm missing

Post by Red Blaze »

This is the bit of code I'm using to determine if the item is stored in the database or not:

Code: Select all

<?php
$filenamevalue = $row_call_photos['photo_filename'];
?>
<input name="filename[]" type="checkbox" id="filename[]" value="<?php echo $filenamevalue; ?>" <?php if
(!(strcmp($filenamevalue, $row_selecteditems['itemname']))) {echo "checked=\"CHECKED\"";}
?>>
In an example, I have a set of 4 photos in the database. I select 2 via checkbox, and click submit. Those 2 get recorded in a different table. When I go back to the photo selection page, 2 check boxes should be checked. The two selected. However, only one is checked. I'm not sure what I'm doing wrong. I'm doing the same thing as in the drop down forms, just changing some variables. Help would be well appreciated. Thank you.

~RB
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

with the small amount of code posted, it's difficult to suggest anything.
Red Blaze
Forum Commoner
Posts: 40
Joined: Mon Mar 27, 2006 3:45 pm

Post by Red Blaze »

Here's the whole code in txt, since it's a tad too long.
http://www.chaossanctum.com/work/code.txt
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

7K in code is nothing. The code:

Code: Select all

<?php require_once('../Connections/prophot.php'); ?>
<?php
if (!isset($_SESSION)) {
  session_start();
}
$aid = $_POST['aid'];
if($_POST['aid'] == ''){
$aid = $_SESSION['Album_ID'];
}
$userid = $_SESSION['MM_UserID'];

$colname_call_photos = "-1";
mysql_select_db($database_prophot, $prophot);
$query_call_photos = sprintf("SELECT * FROM gallery_photos WHERE photo_album = $aid", $colname_call_photos);
$call_photos = mysql_query($query_call_photos, $prophot) or die(mysql_error());
$row_call_photos = mysql_fetch_assoc($call_photos);
$totalRows_call_photos = mysql_num_rows($call_photos);

$colname_call_albums = "-1";
mysql_select_db($database_prophot, $prophot);
$query_call_albums = sprintf("SELECT * FROM gallery_albums WHERE album_id = $aid", $colname_call_albums);
$call_albums = mysql_query($query_call_albums, $prophot) or die(mysql_error());
$row_call_albums = mysql_fetch_assoc($call_albums);
$totalRows_call_albums = mysql_num_rows($call_albums);

mysql_select_db($database_prophot, $prophot);
$query_selecteditems = 'SELECT * FROM items WHERE userid = "'. $userid .'" AND albumid = "'. $aid .'" AND lockedcart = "'. 0 .'"';
$selecteditems = mysql_query($query_selecteditems, $prophot) or die(mysql_error());
$row_selecteditems = mysql_fetch_assoc($selecteditems);
$totalRows_selecteditems = mysql_num_rows($selecteditems);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Viewing <?php echo $row_call_albums['album_name']; ?></title>
<script type="text/JavaScript">
<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
<!-- Meta Tags -->
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="robots" content="index, follow" />

<!-- CSS -->
<link rel="stylesheet" href="css/default.css" media="screen,projection" type="text/css" />
<link rel="stylesheet" href="css/lightbox.css" media="screen,projection" type="text/css" />

<!-- JavaScript -->
<script type="text/javascript" src="scripts/prototype.js"></script>
<script type="text/javascript" src="scripts/lightbox.js"></script>
<style type="text/css">
<!--
body {
	margin: 0px;
	padding: 0px;
	background-color: #000000;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	color: #FFFFFF;
	font-size: 12px;
}
.footer {
	font-size: 9px;
}
.buttons {
	color: #FFFFFF;
	background-color: #000000;
	border: thin solid #656565;
}
.space {
	padding: 20px;
}
a:link {
	color: #FFFFFF;
	text-decoration: none;
}
a:visited {
	color: #FFFFFF;
	text-decoration: none;
}
a:hover {
	color: #CCCCCC;
	text-decoration: underline;
}
a:active {
	color: #FFFFFF;
	text-decoration: underline;
}

-->
</style>
</head>

<body onload="start()">
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td align="left" valign="top">
  <a href="../index.php"><img src="logo_gallery.jpg" border="0" /></a></td>
<td align="right" valign="top">
<img src="../images/filmstrip.gif" /></td>
</tr>
</table>
<form action="placeorder.php" method="post">
<input name="aid" type="hidden" id="aid" value="<?php echo $aid; ?>" />
<br />
<div align="center">
  <table align="center" cellspacing="10">
  <tr>
  <td colspan="4" align="right">
  	Sizes
  	<select name="defaultsize" id="defaultsize">
  <?php
  $sizes = $row_call_albums['sizes'];  
$arr = explode(" ",$sizes);
foreach ($arr as $value) {

mysql_select_db($database_prophot, $prophot);
$query_callsize = "SELECT * FROM sizes WHERE sizeid = ". $value ."";
$callsize = mysql_query($query_callsize, $prophot) or die(mysql_error());
$row_callsize = mysql_fetch_assoc($callsize);
$totalRows_callsize = mysql_num_rows($callsize);
  ?>
    <option value="<?php echo $row_callsize['size']; ?>"><?php echo $row_callsize['size']; ?></option>
	<?php
	}
	?>
  </select>
	<?php
	if($_SESSION['MM_UserID'] == ''){
?>
To place an order, <a href="login.php?code=<?php echo $passcode; ?>">please login</a>.</td>
<?php
}else{
?>
<input name="Submit" type="submit" class="buttons" value="Place Order" /></td>
<?php
	}
	?>  </td>
  </tr>
    <tr>
      <?php

// Variable to handle the number of columns
$newline = 0;

do { 

?>
      <td width="100" height="100" align="center" bgcolor="#2d2b2c" class="space"><a href="image.php?photo_id=<?php echo $row_call_photos['photo_id']; ?>" class="lbOn"><img src="<?php echo $images_dir ?>/tb_<?php echo $row_call_photos['photo_filename']; ?>" alt="<?php echo $row_call_photos['photo_filename']; ?>" border="0" /></a><br />
          <?php echo $row_call_photos['photo_filename']; ?>
		  <?php
	if($_SESSION['MM_UserID'] == ''){
//ignore
}else{
$filenamevalue = $row_call_photos['photo_filename'];
?>
<input name="filename[]" type="checkbox" id="filename[]" value="<?php echo $filenamevalue; ?>" <?php if
(!(strcmp($filenamevalue, $row_selecteditems['itemname']))) {echo "checked=\"CHECKED\"";}
?>>
<?php
	}?>
      </td>
      <?php

    // Increase the number of columns displayed
    $newline++;
    if ($newline == "4")
    {
        // Start a new row and reset the $newline variable
        echo ("</tr><tr>\n");
        $newline = 0;
    }    
} while ($row_call_photos = mysql_fetch_assoc($call_photos));

// Add any additional columns if needed to fill the last row
for ($newline; $newline < 4; $newline++)
{
    echo ("<td>&nbsp;</td>\n");
}

?>
    </tr>
	<tr>
	<td align="right" colspan="6">
	<?php
	if($_SESSION['MM_UserID'] == ''){
echo <<<__HTML_END
To place an order, <a href="login.php?code=$passcode">please login</a>.</td>
__HTML_END;
}else{
echo <<<__HTML_END
<input name="Submit" type="submit" class="buttons" value="Place Order" /></td>
__HTML_END;
	}
	?>
	</tr>
  </table>
</div>
</form>
<div align="left">
<span class="footer">Copyright &copy; 2005-2006 -  Pro-Photos.com <br />
All images on the Website are the property of either Pro-Photos.com and/or its members and are protected by international copyright laws.<br />
Use of these Images without license is prohibited. </span>
</div>
</body>
</html>
<?php
mysql_free_result($call_photos);
mysql_free_result($call_albums);
mysql_free_result($selecteditems);
?>
Red Blaze
Forum Commoner
Posts: 40
Joined: Mon Mar 27, 2006 3:45 pm

Post by Red Blaze »

I still can't figure out this problem. Don't I use the same function as a drop down to automatically select the box?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it has to do with your usage of $row_selecteditems. It will only be one record, not information on all the records.
Red Blaze
Forum Commoner
Posts: 40
Joined: Mon Mar 27, 2006 3:45 pm

Post by Red Blaze »

Oh dud! I see it now. I got it fixed, thank you! :D
Post Reply