Page 1 of 1

checkbox search

Posted: Fri Jul 18, 2008 5:51 am
by Mikosww
Hi,
I want to do a search with checkbox, which would receive values from my database. I would be glad if someone told me what is wrong with this script.

index.php

Code: Select all

 
<form name= "priorytet" action="search.php" method="post">
Your choice: 
<input type="checkbox" name="priorytet[]" value="A">A
<input type="checkbox" name="priorytet[]" value="B">B
<input type="checkbox" name="priorytet[]" value="C">C
<input type="submit" value="Search!" />
</form>
 
search.php

Code: Select all

 
<?php
 
$db_name = "xxx";
$connection = @mysql_connect("xxx", "xxx", "xxx") or die("couldn't connect");
$db = @mysql_select_db($db_name, $connection) or die("Couldn't select db");
 
 
function skill_search($priorytet) {
if (!empty($priorytet)) {
$query = "SELECT DISTINCT priorytet
FROM treningi";
 
$query .= " AND (";
foreach ($treningi as $check) {
$query .= " priorytet = $check OR";
}
 
/* remove the final OR */
$query = substr($query, 0, -2);
$query .= ")";
 
$query=mysql_query("SELECT * FROM treningi");
 
while($row=mysql_fetch_array($array))
{
 
echo'<input name="priorytet" type="checkbox" value="' . $row['name'] . '" />
 
?>
 

Re: checkbox search

Posted: Fri Jul 18, 2008 7:33 am
by Reviresco
You're missing the "WHERE" clause in the query.

Re: checkbox search

Posted: Fri Jul 18, 2008 7:56 am
by Mikosww
the error is "Parse error: syntax error, unexpected $end on line 33"

Re: checkbox search

Posted: Fri Jul 18, 2008 8:05 am
by VladSun
Mikosww wrote:the error is "Parse error: syntax error, unexpected $end on line 33"

Code: Select all

while($row=mysql_fetch_array($array))
{
 
echo'<input name="priorytet" type="checkbox" value="' . $row['name'] . '" />
  
?>
 
 
You are missing the ", ; and }

Re: checkbox search

Posted: Fri Jul 18, 2008 8:32 am
by Mikosww
thanks for advices!
But there is still something wrong.
Parse error: syntax error, unexpected T_STRING on line 31.