I have entered some array values using checkboxes into mysql database through a form. Next iam creating a searchpage where all those cateogories inserted through checkboxes has to be retrieved using list/menu box.
When i check only a single checkbox to insert the checked category ,selecting that category through list box gives out the entire data of the user corresponding to that category.
However when i check multiple checkboxes and in the category select all those checked values to find if any user fits in all those category and hence prompt the entire data corresponding to it,the column shows only 'array' and not array values. So please anyone guide me as how should i fetch all the checked categories through the list/menu box.
Here goes the edited code:
Code to insert the array values in mysql database using checkboxes[PHP]
<?
$state=$_POST['state'];
$state = implode(",", $state);
$query="insert into consult (state)VALUES('$state')";
mysql_query($query);
?>
<form name="form" action="abc.php" method ="post">
<input name=state[0] type="checkbox" value="Air Conditioning Consultants & Contractors">Air Conditioning Consultants & Contractors
<input name=state[1] type="checkbox" value="Arbitrators" >Arbitrators
<input name=state[2] type="checkbox" value=Builders,Contractors & Developers>Builders,Contractors & Developers
<input name=state[3] type="checkbox" value=Civil Engineers and Contactors>
Civil Engineers and Contactors
</form>
<input name="submit" type="submit" class="style40" value="Submit">
[/PHP]
Code to fetch those checked array values using list/menu box.[PHP]
<?php
if (isset($_POST['submit']))
{
$state=$_POST['state'];
$state=explode(",",$state);
}
?>
<form name="form1" action="cons_show.php" method="post" >
<select name="state">
<option selected >Select</option>
<option value="Air Conditioning Consultants & Contractors">Air Conditioning Consultants & Contractors</option>
<option value="Arbitrators">Arbitrators</option>
<option value="Builders,Contractors & Developers">Builders,Contractors & Developers</option>
<option value="Civil Engineers and Contractors">Civil Engineers and Contractors</option>
</form>
if(!isset($cmd)) {
$state=$_POST['state'];
$query = @mysql_query("SELECT * FROM consult where state='$state'");
if (!$query)
{
exit('<p>Error retrieving entries from database!<br/>'.'Error: ' . mysql_error() . '</p>');
}
$sql = mysql_fetch_array($query);
if($sql){
echo '<table width="90%" cellspacing="2" cellpadding="4" border="1"><tr><td valign="top">
<table><tr><td ><h4 ><u> Customer Information</u> </h4></td></tr></table>';
echo '<table cellpadding="4"><tr><td ><b>Firm Name</b></td><td ><b>State</b></td><td><b>City</b></td>
<td><b>Contact</b></td><td><b>Email Address</b></td></tr>';
$firm = $sql['firmname'];
$address = $sql['adress'];
$city= $sql['city'];
$pin=$sql['pin'];
$tel=$sql['tel'];
$fax=$sql['fax'];
$email=$sql['email'];
$state=$sql['state'];
echo "<tr><td><a href='cons_details.php?cmd=edit&STATE=$state'>$fir m</a></td><td>$state</td><td>$city</td><td>$tel</td><td>$email</td>";
echo "<td>";
echo "</tr></table>";
}
else {
echo '<table ><tr><td>';
[/PHP]
This is how i have worked.but it is only useful for only a single checked data and cease to work on multiple checked data.
So if anyone ca help please do it.
Thanks and Regards
TechnoAtif