Checkboxes not submitting

I’m an experienced programmer, and I’ve done this a hundred times, but for some reason it’s not working, and it’s driving me insane.

Here’s the short version first:

Here’s where they sit inside my form:

<div class="scroll_checkboxes">
<?php echo $options; ?>
</div>

Here is what populates the div. The below line is placed in a properly working while loop (mysql_fetch_array):

$options .= "<input type=\\"checkbox\\" name=\\"mayNeed[]\\" value=\\"$id\\" /> $id - $product_name - $modelNumber<br />";

And here is where I’m trying to grab it after a submit:

$tester = "";
if(isset($_POST['mayNeed']))
{
		
	$likeArray = $_POST['mayNeed'];
	foreach($likeArray as $item)
	{
		
		$tester .= $item;
			
	}
		
} else {
	echo "<h1>IT'S NOT WORKING!</h1>";
}

It’s not working. I get the results of my else statement instead. For some reason it is not setting the POST.

Here’s the long version in case you want to or need to see all of my code. Most of it is superfluous to this problem, but here you go:

<?php include('credentials.php');?>

<?php
// Error Reporting

	error_reporting(E_ALL);
	ini_set('display_errors', '1');	

?>


<?php
// Delete items

if(isset($_GET['deleteid'])) {
	
	echo "Are you sure you want to delete product with the ID " .$_GET['deleteid'].'? <a href="inventory_list.php?yesdelete='.$_GET['deleteid'].'">Yes</a> | <a href="inventory_list.php">No</a>';
	exit();
}

if(isset($_GET['yesdelete'])) {
	// remove item from system and delete its picture
	
	$id_to_delete = $_GET['yesdelete'];
	$sql = mysql_query("delete from products where id='$id_to_delete' limit 1") or die(mysql_error());
	
	$pic_to_delete = ("../inventoryImages/$id_to_delete.jpg");
	if(file_exists($pic_to_delete)) {
		unlink($pic_to_delete);
	}
	
	header("location: inventory_list.php");
	exit();
	
}
?>

<?php
// Parse form data and add inventory item
$tester = "";
if(isset($_POST['mayNeed']))
{
		
	$likeArray = $_POST['mayNeed'];
	foreach($likeArray as $item)
	{
		
		$tester .= $item;
			
	}
		
} else {
	echo "<h1>IT'S NOT WORKING!</h1>";
}

	if(isset($_POST['product_name'])) {
		
		$product_name = mysql_real_escape_string($_POST['product_name']);
		$model_number = mysql_real_escape_string($_POST['model_number']);
		$price = mysql_real_escape_string($_POST['price']);
		$quantity = mysql_real_escape_string($_POST['quantity']);
		$category = mysql_real_escape_string($_POST['category']);
		$subcategory = mysql_real_escape_string($_POST['subcategory']);
		$details = mysql_real_escape_string($_POST['details']);
		
			
		if($category == "loungeSeats"){
			$category = 6;
		} else if($category == "jumpSeats") {
			$category = 7;
		} else if($category == "bolsterSeats") {
			$category = 1;
		} else if($category == "bucketSeats") {
			$category = 4;
		}
		
		$sql = mysql_query("select id from products where product_name = '$product_name' limit 1");
		$productMatch = mysql_num_rows($sql);
		if($productMatch > 0) {
			echo "Sorry, you tried to place a duplicate product name into the system. <a href='inventory_list.php'>Click Here</a>";
			exit();
		}
		
		$sql = mysql_query("insert into products (product_name, model_number, price, quantity, details, category, subcategory, date_added) values ('$product_name', '$model_number', '$price', '$quantity', '$details', '$category', '$subcategory', now())") or die(mysql_error());
		$pid = mysql_insert_id();
		$newname = "$pid.jpg";
		move_uploaded_file($_FILES['fileField']['tmp_name'],"../inventoryImages/$newname");
		
		header("location: inventory_list.php");
		exit();
		
	}
?>


<?php
// Grabs list for viewing
	
	$product_list = "";
	$options = false;
	$sql = mysql_query("select * from products");
	$product_count = mysql_num_rows($sql);
	
	if($product_count > 0){
		while($row = mysql_fetch_array($sql)) {
			$id = $row['id'];
			$product_name = $row['product_name'];
			$modelNumber = $row['model_number'];
			$price = $row['price'];
			$quantity = $row['quantity'];
			$date_added = strftime("%b %d, %Y", strtotime($row['date_added']));
			$product_list .= "
			<tr>
			<td>Product ID: $id</td>
			<td><strong>$product_name</strong></td>
			<td>$modelNumber</td>
			<td>$$price</td>
			<td>$quantity</td>
			<td>$date_added</td>
			<td><a href='inventory_edit.php?pid=$id'>edit</a> &bull; <a href='inventory_list.php?deleteid=$id'>delete</a></td>
			</tr>";
			$options .= "<input type=\\"checkbox\\" name=\\"mayNeed[]\\" value=\\"$id\\" /> $id - $product_name - $modelNumber<br />";
		}
	} else {
		$product_list = "You have not products listed in your store yet.";
	}


?>

<html>
<head>
<title>Inventory List</title>
<link rel="stylesheet" type="text/css" href="../style/styles.css" />
<script type="text/javascript" src="../jquery-1.7.1.min.js"></script>

<script type="text/javascript">

$(function() {
	
	$('.list tr:even').css('background-color', '#999');
	
});

</script>

<script type="text/javascript" language="javascript">

function validateMyForm(){
	var isValid = true;

	if(document.myForm.product_name.value==""){
		alert("Please enter a product name");
		isValid = false;
	} else if (document.myForm.price.value=="") {
		alert("Please enter a price");
		isValid = false;
	} else if (document.myForm.category.value=="") {
		alert("Please enter a category");
		isValid = false;
	} else if (document.myForm.details.value=="") {
		alert("Please enter a description");
		isValid = false;
	} else if (document.myForm.fileField.value=="") {
		alert("Please upload a file");
		isValid = false;
	}
	return isValid;
}
</script>
</head>

<body>
	<div id="mainWrapper">
		<div id="pageHeader">
			<br />
		</div>
		
		<div id="pageContent">
			
			<div id="navcontainer">
				<?php include("../inlineNav.php"); ?>
			</div>
			
			<div style="text-align: right; padding-right: 20px">
				<a href="inventory_list.php#inventoryForm">+Add New Item</a>
				</div>
			<div style="margin-left: 24px">
				
				<h2>Inventory List</h2>

                <table width=90% border=1 class="list">
                <tr>
                <th>Product ID</th>
                <th>Product Name</th>
                <th>Model Number</th>
                <th>Price</th>
                <th>Quantity</th>
                <th>Date</th>
                <th>Admin</th>
                </tr>

				<?php echo $product_list; ?>

                </table>
				
			</div>
			
			<div style="margin-left: 24px">
				<a name="inventoryForm" id="inventoryForm"></a>
				<h2>New Item Form</h2>
				<form action="inventory_list.php" enctype="multipart/form-data" name="myForm" id="myForm" method="post">
				
				<table width=90%>
				
				<tr>
					<td width=20%>Product Name</td>
					<td width=80%>
						<label>
						<input type="text" name="product_name" id="product_name" size="64" />
						</label>
					</td>
				</tr>
                <tr>
                	<td width=20%>Model Number</td>
                    <td width=80%>
                    	<label>
                        <input type="text" name="model_number" id="model_number" size="12" />
                        </label>

                    </td>
                </tr>
				<tr>
					<td width=20%>Product Price</td>
					<td width=80%>
						<label>
						$<input type="text" name="price" id="price" size="12" />
						</label>					
					</td>
				</tr>
                <tr>
                	<td width=20%>Quantity</td>
                    <td width=80%>
                    	<label>
                        <input type="text" name="quantity" id="quantity" size="5" />
                        </label>
                        </td>
                        </tr>

								<tr>
					<td width=20%>Category</td>
					<td width=80%>
						<label>
						<select name="category" id="category">
							<option value=""></option>
							<option value="bolsterSeats">Bolster Seats</option>
							<option value="bucketSeats">Bucket Seats</option>
							<option value="camo">Camo</option>
							<option value="fishingSeats">Fishing Seats</option>
                            <option value="jumpSeats">Jump Seats</option>
                            <option value="loungeSeats">Lounge Seats</option>
						</select>
						</label>
					</td>
				</tr>
				<tr>
					<td width=20%>Subcategory</td>
					<td width=80%>
						<label>
						<select name="subcategory" id="subcategory">
							<option value=""></option>
							<option value="none">None</option>
						</select>
						</label>
					</td>
				</tr>
                <tr>
                	<td width=20%>Like Items</td>
                    <td width=80%>
                    	
                        <div class="scroll_checkboxes">
                        	<?php echo $options; ?>
                      	</div>

                        </td>
                        </tr>
								<tr>
					<td width=20%>Product Details</td>
					<td width=80%>
						<label>
						<textarea name="details" id="details" cols="64" rows="5"></textarea>
						</label>
					</td>
				</tr>
				<tr>
					<td width=20%>Product Image</td>
					<td width=80%>
						<label>
						<input type="file" name="fileField" id="fileField" />
						</label>
					</td>
				</tr>
								<tr>
					<td></td>
					<td>
						<label>
						<input type="submit" name="button" id="button" value="Add this item now" onClick="javascript:return validateMyForm();" />
						</label>
					</td>
				</tr>
				
				</table>
				
				</form>
			
			
		</div>
		
		<div id="pageFooter">
			
		</div>
		
	</div>

I don’t see anything blatantly missing…a couple questions:

  1. Can we see the html output from the display of $output? Is there a value in the value field?
  2. Are any checkboxes checked when the form is submitted? If not, there will be no value returned in the _POST field.

There are checkboxes checked. Here is the output when the page is rendered:

<div class="scroll_checkboxes">

<input type="checkbox" name="mayNeed[]" value="11" /> 11 - Lounge Seat - Red - 5902106<br /><input type="checkbox" name="mayNeed[]" value="12" /> 12 - Lounge Seat - Blue - 5902104<br /><input type="checkbox" name="mayNeed[]" value="13" /> 13 - Lounge Seat - Light Blue - 5902103<br /><input type="checkbox" name="mayNeed[]" value="14" /> 14 - Lounge Seat - Light Taupe - 5902102<br /><input type="checkbox" name="mayNeed[]" value="15" /> 15 - Lounge Seat - Gray - 5902101<br /><input type="checkbox" name="mayNeed[]" value="16" /> 16 - Lounge Seat - White - 5902100<br /><input type="checkbox" name="mayNeed[]" value="17" /> 17 - Lounge Seat  - White - 5907100<br /><input type="checkbox" name="mayNeed[]" value="18" /> 18 - Lounge Seat  - Gray - 5907101<br /><input type="checkbox" name="mayNeed[]" value="19" /> 19 - Lounge Seat  - Light Taupe - 5907102<br /><input type="checkbox" name="mayNeed[]" value="20" /> 20 - Lounge Seat  - Light Blue - 5907103<br /><input type="checkbox" name="mayNeed[]" value="21" /> 21 - Lounge Seat  - Blue - 5907104<br /><input type="checkbox" name="mayNeed[]" value="22" /> 22 - Lounge Seat  - Red - 5907106<br /><input type="checkbox" name="mayNeed[]" value="23" /> 23 - Lounge Seat  - White/Teal - 5908202<br /><input type="checkbox" name="mayNeed[]" value="24" /> 24 - Lounge Seat  - White/Medium Blue - 5908201<br /><input type="checkbox" name="mayNeed[]" value="25" /> 25 - Lounge Seat  - Gray/Blue/Light Blue - 5915310<br /><input type="checkbox" name="mayNeed[]" value="26" /> 26 - Lounge Seat  - Gray/Red/Charcoal - 5915311<br /><input type="checkbox" name="mayNeed[]" value="27" /> 27 - Lounge Seat - White/Light Taupe/Burgundy - 5915301 <br /><input type="checkbox" name="mayNeed[]" value="28" /> 28 - Lounge Seat  - White/Light Taupe/Navy  - 5915300<br /><input type="checkbox" name="mayNeed[]" value="29" /> 29 - Jump Seat  - Light Taupe/Brown - 5910221<br /><input type="checkbox" name="mayNeed[]" value="30" /> 30 - Jump Seat  - Gray/Medium Red/Charcoal - 5914311<br /><input type="checkbox" name="mayNeed[]" value="31" /> 31 - Jump Seat  - White/Light Blue - 5910201<br /><input type="checkbox" name="mayNeed[]" value="32" /> 32 - Jump Seat  - White/Light Taupe - 5910200<br /><input type="checkbox" name="mayNeed[]" value="33" /> 33 - Jump Seat - White/Teal - 5910202 <br /><input type="checkbox" name="mayNeed[]" value="34" /> 34 - Jump Seat  - White - 5909100<br /><input type="checkbox" name="mayNeed[]" value="35" /> 35 - Jump Seat  - Light Taupe - 5909102<br /><input type="checkbox" name="mayNeed[]" value="36" /> 36 - Bucket Seat  - White/Light Taupe/Medium Taupe - 5932340<br /><input type="checkbox" name="mayNeed[]" value="37" /> 37 - Deluxe Lounge Seat - Gray/Teal - 5920216 <br /><input type="checkbox" name="mayNeed[]" value="38" /> 38 - Lounge Seat  - Gray/Medium Red - 5908502<br /><input type="checkbox" name="mayNeed[]" value="39" /> 39 - Bucket Seat  - Light Taupe/Brown/Medium Taupe - 5932326<br /><input type="checkbox" name="mayNeed[]" value="40" /> 40 - Bucket Seat  - Gray/Berry/Charcoal - 5932336<br /><input type="checkbox" name="mayNeed[]" value="41" /> 41 - Jump Seat - Gray/Charcoal - 5921213<br /><input type="checkbox" name="mayNeed[]" value="42" /> 42 - Jump Seat - Gray/Berry - 5921214<br /><input type="checkbox" name="mayNeed[]" value="43" /> 43 - Jump Seat - Gray/Burgundy/Charcoal - 5931336<br />                      	</div>