Can somebody help me to retreive one or more checkbox values from the database using php and MySQL? Thanks and I appreciate that.:)
In checkbox.html file the checkbox as follow:
<form method="post" action="Process.php">
<fieldset>
<legend>Choose feature(s) to search for apartment</legend>
<table border="0">
<tr>
<td><input type="checkbox" name="feature[]" value="walkincloset">Walk in closet</td>
<td><input type="checkbox" name="feature[]" value="storage">storage</td>
<td><input type="checkbox" name="feature[]" value="availability">availability</td>
</tr>
<tr>
<td><input type="submit" value="Select"></td>
</tr>
</table>
</fieldset>
</form>
The code is follow in Process.php
<?php
$featurex= $_POST['feature'];
@ $db = new mysqli('localhost', 'root', 'Password', 'Database Name');
if (mysqli_connect_errno()) {
echo 'Error: Could not connect to database. Please try again later.';
exit;
}
$query = "select * from apartment where WHERE walkincloset ='$featurex' or storage= ‘ $feature’ or availability=’$feature’ ";
$result = $db->query($query);
$num_results = $result->num_rows;
echo "<p>Number of apartments found: ".$num_results."</p>";
for ($i=0; $i <$num_results; $i++) {
$row = $result->fetch_assoc();
echo "<p><strong>".($i+1).". Apartment number: ";
echo htmlspecialchars(stripslashes($row['aptno']));
echo "</strong><br />Rent Price: ";
echo stripslashes($row['pricerent']);
echo "<br />Number of rooms: ";
echo stripslashes($row['noofroom']);
echo "<br />Number of bathrooms: ";
echo stripslashes($row['noofbath']);
echo "<br />Apartment area: ";
echo stripslashes($row['area']);
echo "<br />Walk in closet: ";
echo stripslashes($row['walkincloset']);
echo "<br />Storage: ";
echo stripslashes($row['storage']);
echo "<br />Availability: ";
echo stripslashes($row['availability']);
echo "<br />Apartment photo: ";
echo stripslashes($row['aptphoto']);
echo "<br />Building number: ";
echo stripslashes($row['bldno']);
echo "</p>";
}
$result->free();
$db->close();
?>