I have this code:

foreach( $_POST[ 'count' ] as $textBoxIndex => $textBoxValue ) {

echo '<br />Textbox ' . $textBoxIndex . ' has value [' . $textBoxValue . ']';

}

This loops through a series of text boxes with have been created with this:

<while($rowequipment = mysql_fetch_assoc($sqlequipment)) {
echo '<input type="checkbox" name="equipment[]"value="'.$rowequipment['equipmentid'].'"/>
<input type="text" name="count[]" id="count[]" size="3" value=""/>'
.$rowequipment['description']."<br />";
}

The purpose here is to try and create a system by which the user can input how many of each peice of equipment they want and store it in the database.

However the problem is that the first peice of code is going through the blank textboxes as well and returning null pieces of data which i cannot insert into the database.

My question is how would i use the first peice of code but not print out the text boxes which have no value?

Thanks.

Just test if the value is empty or null with empty() function.

foreach( $_POST[ 'count' ] as $textBoxIndex => $textBoxValue ) {
    if( !empty($textBoxValue) )
        echo '<br />Textbox ' . $textBoxIndex . ' has value [' . $textBoxValue . ']';
}

Cheers!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.