Hi,
I’m pretty new to PHP and MySQL and I wanted to create a search engine with checkboxes. In my database are names of our programmers and what programming languages they can write.
I got one (.html) form and one (.php) file that searches the database. Every time I try to connect to the database, I get a blank page?! Could someone help me, I don’t know what’s wrong. Below you can find the tables and files.
Search.php:
<?php
$db_name = "checksearch";
$connection = @mysql_connect("localhost", "Bobo", "password_doesnt_matter" or die("couldn't connect"
$db = @mysql_select_db($db_name, $connection) or die("Couldn't select db"
/* builds a query to search for the skills
checked off in the $skills array */
function skill_search($skills) {
if (!empty($skills)) {
$query = "SELECT DISTINCT members.membername
FROM members, const_skills, lookup_skills
WHERE lookup_skills.uid = user.id
AND lookup_skills.skill_id = const_skills.id ";
$query .= " AND (";
foreach ($skills as $check) {
$query .= " const_skills.id = $check OR";
}
/* remove the final OR */
$query = substr($query, 0, -2);
$query .= "";
$count = count($skills);
$query .= " GROUP BY members.membername HAVING count(members.membername) >= $count";
$query .= ";";
return $query;
}
}
?>
form.html:
SQL tables:
const_skills:
id: value:
1 PHP
2 ASP
3 Perl
4 JavaScript
5 JSP
6 Coldfusion
lookup_skills:
id: uid: skill_id:
1 1 1
2 1 3
3 1 4
4 1 6
5 2 1
6 2 4
7 2 6
8 3 1
9 3 3
10 3 4
11 3 5
12 3 6
13 4 2
members:
id: membername:
1 John
2 Dan
3 Bob
4 Robin
Could somebody please help, that would be great!,
Bobo
P.S. the "<" and ">" were replaced by the "[" and "]", it's not a mistake! hehehe
I’m pretty new to PHP and MySQL and I wanted to create a search engine with checkboxes. In my database are names of our programmers and what programming languages they can write.
I got one (.html) form and one (.php) file that searches the database. Every time I try to connect to the database, I get a blank page?! Could someone help me, I don’t know what’s wrong. Below you can find the tables and files.
Search.php:
<?php
$db_name = "checksearch";
$connection = @mysql_connect("localhost", "Bobo", "password_doesnt_matter" or die("couldn't connect"
$db = @mysql_select_db($db_name, $connection) or die("Couldn't select db"
/* builds a query to search for the skills
checked off in the $skills array */
function skill_search($skills) {
if (!empty($skills)) {
$query = "SELECT DISTINCT members.membername
FROM members, const_skills, lookup_skills
WHERE lookup_skills.uid = user.id
AND lookup_skills.skill_id = const_skills.id ";
$query .= " AND (";
foreach ($skills as $check) {
$query .= " const_skills.id = $check OR";
}
/* remove the final OR */
$query = substr($query, 0, -2);
$query .= "";
$count = count($skills);
$query .= " GROUP BY members.membername HAVING count(members.membername) >= $count";
$query .= ";";
return $query;
}
}
?>
form.html:
HTML:
[body]
[br]
[form name="skills" method="POST" action="search.php"]
Check off your web development skills:
[table width="400" border="0"]
[tr]
[td][input type="checkbox" name="skills[]" value="1"]PHP[/td]
[td][input type="checkbox" name="skills[]" value="2"]ASP[/td]
[td][input type="checkbox" name="skills[]" value="3"]Perl[/td][/tr]
[tr][td][input type="checkbox" name="skills[]" value="4"]JavaScript[/td]
[td][input type="checkbox" name="skills[]" value="5"]JSP[/td]
[td][input type="checkbox" name="skills[]" value="6]Coldfusion[/tr]
[tr][/table]
[br]
[input type="submit" value="Submit"]
[/form]
[/body]
SQL tables:
const_skills:
id: value:
1 PHP
2 ASP
3 Perl
4 JavaScript
5 JSP
6 Coldfusion
lookup_skills:
id: uid: skill_id:
1 1 1
2 1 3
3 1 4
4 1 6
5 2 1
6 2 4
7 2 6
8 3 1
9 3 3
10 3 4
11 3 5
12 3 6
13 4 2
members:
id: membername:
1 John
2 Dan
3 Bob
4 Robin
Could somebody please help, that would be great!,
Bobo
P.S. the "<" and ">" were replaced by the "[" and "]", it's not a mistake! hehehe