Jump to content

PHP MYSQL search with checkboxes


compgeek83

Recommended Posts

having a small issue setting up a search, trying to use check boxes, here is my form code

 

<form action="workorder_index.php" method="POST">
<input type="checkbox" name="wos_0" <? if($wos_0 != NULL) { echo "checked"; }?>>0 - Active
<input type="checkbox" name="wos_1" <? if($wos_1 != NULL) { echo "checked"; }?>>1 - Completed awaiting pickup
<input type="checkbox" name="wos_2" <? if($wos_2 != NULL) { echo "checked"; }?>>2 - Completed and out the door
<input type="checkbox" name="wos_3" <? if($wos_3 != NULL) { echo "checked"; }?>>3 - Waiting call back
<input type="checkbox" name="wos_4" <? if($wos_4 != NULL) { echo "checked"; }?>>4 - Waiting for parts<br>
<input type="checkbox" name="wos_5" <? if($wos_5 != NULL) { echo "checked"; }?>>5 - Parts in waiting for completion
<input type="checkbox" name="wos_6" <? if($wos_6 != NULL) { echo "checked"; }?>>6 - not used
<input type="checkbox" name="wos_7" <? if($wos_7 != NULL) { echo "checked"; }?>>7 - Overdue for pickup
<input type="checkbox" name="wos_8" <? if($wos_8 != NULL) { echo "checked"; }?>>8 - Scrapped per customer
<input type="checkbox" name="wos_9" <? if($wos_9 != NULL) { echo "checked"; }?>>9 - Scrapped by overdue<br><br>
<input type="hidden" value="1" name="customsearch">
<input type="Submit" value="Update">
</form>

 

here is my handling code

 

$wos_0=$_POST[wos_0];
$wos_1=$_POST[wos_1];
$wos_2=$_POST[wos_2];
$wos_3=$_POST[wos_3];
$wos_4=$_POST[wos_4];
$wos_5=$_POST[wos_5];
$wos_6=$_POST[wos_6];
$wos_7=$_POST[wos_7];
$wos_8=$_POST[wos_8];
$wos_9=$_POST[wos_9];

if(isset($_POST['customsearch'])) {
$str='';
if($wos_0 != NULL) {
	$str.= "'0'";
}
if($wos_1 != NULL) {
	$str.= ",'1'";
}
if($wos_2 != NULL) {
	$str.= ",'2'";
}
if($wos_3 != NULL) {
	$str.= ",'3'";
}
if($wos_4 != NULL) {
	$str.= ",'4'";
}
if($wos_5 != NULL) {
	$str.= ",'5'";
}
if($wos_6 != NULL) {
	$str.= ",'6'";
}
if($wos_7 != NULL) {
	$str.= ",'7'";
}
if($wos_8 != NULL) {
	$str.= ",'8'";
}
if($wos_9 != NULL) {
	$str.= ",'9'";
}

$query="SELECT * FROM workorders a INNER JOIN customers b ON a.customer_id = b.customer_id WHERE a.workorder_status IN (".$str.") ORDER BY a.workorder_id";

}

 

everything works as intended as long as the first check box remains checked, the others can be checked or not, if the first box gets unchecked I get this error

 

SELECT * FROM workorders a INNER JOIN customers b ON a.customer_id = b.customer_id WHERE a.workorder_status IN (,'1','2','3','4','5','6','7','8','9') ORDER BY a.workorder_id

Warning: mysql_numrows() expects parameter 1 to be resource, boolean given in workorder_index.php on line 84

 

basically I can't get the commas right, ...? any help is much appreciated

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.