Forum Moderators: coopster
I've done the checkbox form - where they can choose music type:
<form action="page4.php" method="post">
<input type="checkbox" name="type[]" value="blues">
<input type="checkbox" name="type[]" value="r&b">
<input type="checkbox" name="type[]" value="pop">
<input type="checkbox" name="type[]" value="rock">
<input type="submit" name="submit" value="Compare">
</form>
I'VE DONE THE HTML pointing to the music type (I think..) but can't get any output - any ideas? I suspect its the coding but i've got lost somewhere...!
<?php
mysql_connect("localhost","","") or die("Unable to connect to SQL server");
@mysql_select_db("musicdb1") or die("Unable to select database");
$type = $_POST['type'];
if (!empty($type))
{
for ($i=0; $i<count($search); $i++)
{
$sql = "select * from type WHERE type =" . $_POST['type'] . " and type='" . $_POST['type'] . "'";
echo $sql;
$query = mysql_query($sql);
while ($row = mysql_fetch_array($query)) {
echo "<p>",$row['id'],": ",$row['type'];
}
}
?>
<?
$type = $_POST['type'];
if (!empty($type))
{
for ($i = 0; $i < count($type); $i++)
{
$sql = "SELECT * FROM `type` WHERE `type` = '".$type[$i]."'";
echo $sql;
$query = mysql_query($sql) or die("Oops an error: ".mysql_error());
while ($row = mysql_fetch_array($query))
{
echo "<p>",$row['id'],": ",$row['type'];
}
}
?>
In my humble opinion, this is not the best way of doing this but it should work ok.
Please note: untested code ;-)
If you have any more problems please let me know ...
Del
error_reporting(E_ALL); // add this as the first line of your script
In addition to scriptmasterdel's suggestions, also please make use of the mysql_real_escape_string [php.net] function to prevent SQL injection attacks [php.net].