我在我的localhost服务器上测试的这个程序有问题。每次我在表单中输入值并从下拉菜单中选择一个课程时,我收到错误消息(其中“....”是我选择的课程名称):
Unknown column '.....' in 'where clause'
EDIT2这是我用来创建具有完整索引的表的代码:
include 'login.php';
$link = mysql_connect(HOST, USER, PASS) or die (mysql_connect_error());
mysql_select_db('graham', $link);
$query1 = "CREATE TABLE course (name VARCHAR(50), code VARCHAR(10), max INT(2))";
$query2 = "CREATE TABLE students (name VARCHAR(50), studentnum VARCHAR(50), FULLTEXT (name,studentnum))ENGINE=MyISAM";
$query3 = "CREATE TABLE enrolled (student VARCHAR(50), studentnum VARCHAR(50), course VARCHAR(50), FULLTEXT (student,studentnum,course))ENGINE=MyISAM";
$result1 = mysql_query ($query1, $link) or die(mysql_error());
$result2 = mysql_query ($query2, $link) or die(mysql_error());
$result3 = mysql_query ($query3, $link) or die(mysql_error());
$querya = "ALTER TABLE students ADD FULLTEXT(name)";
$queryb = "ALTER TABLE students ADD FULLTEXT(studentnum)";
$queryc = "ALTER TABLE enrolled ADD FULLTEXT(student)";
$queryd = "ALTER TABLE enrolled ADD FULLTEXT(studentnum)";
$querye = "ALTER TABLE enrolled ADD FULLTEXT(course)";
$result4 = mysql_query ($querya, $link) or die(mysql_error());
$result5 = mysql_query ($queryb, $link) or die(mysql_error());
$result6 = mysql_query ($queryc, $link) or die(mysql_error());
$result7 = mysql_query ($queryd, $link) or die(mysql_error());
$result8 = mysql_query ($querye, $link) or die(mysql_error());
$query4 = mysql_query("INSERT INTO course (name, code, max)
VALUES
('HTML', 'PROG-1288', 4),
('Javascript', 'PROG-2283', 3),
('Dreamweaver','MEDA-1380', 4),
('Photoshop','PHOT-1382', 3)") or die (mysql_error());
$query5 = mysql_query("INSERT INTO students (name, studentnum)
VALUES
('GerrardLooper', 987654),
('BruceLee', 123456),
('JoeSchmoe', 236728),
('JaneDoe', 111222),
('JoeSchmoe', 128790)") or die (mysql_error());
$sql = "SELECT name FROM course";
$result = mysql_query($sql) or die (mysql_error());
echo "<form action='index.php' method='post'><pre>";
echo "Please select a course: ";
echo "<select name='coursename'>";
while ($row = mysql_fetch_array($result)) {
echo "<option value='" . $row['name'] ."'>" . $row['name'] ."</option>";
}
echo "</select>";
echo "\nStudent Name <input type='text' name='studentname' />";
echo "\nStudent Number <input type='text' name='studentnum' />\n";
echo "<input type='submit' name='addrecord' value='ADD RECORD' />";
echo "</pre></form>";
mysql_close($link);
以下是我在尝试将用户选择的内容与表格中的数据进行匹配时使用的代码:
//check if name and student number match the records in the database
$name1 = mysql_real_escape_string($_POST['studentname']);
$num = mysql_real_escape_string($_POST['studentnum']);
$qw = "SELECT name FROM students WHERE MATCH (name) AGAINST ('".$name1."')";
$qw1 = "SELECT studentnum FROM students WHERE MATCH (studentnum) AGAINST ('".$num."')";
$namematch = mysql_query($qw) or die(mysql_error());
$nummatch = mysql_query($qw1) or die(mysql_error());
if (($namematch || $nummatch) == FALSE) {
die('Name or student number do not match those on record');
}
答案 0 :(得分:1)
MATCH(...)AGAINST语法只能与FULLTEXT索引一起使用。尝试将FULLTEXT索引添加到相关列中,如下所示:
ALTER TABLE students ADD FULLTEXT(name);
ALTER TABLE students ADD FULLTEXT(studentnum);