抱歉,这是一个重复的问题,但由于某种原因,我无法对收到的答案发表任何评论,并且该问题尚未得到解答。
当我的表单被提交(通过 Ajax)时,我收到以下错误消息:
PHP 警告:
mysqli_query()
[function.mysqli-query]:第 32 行 /home1/xenongro/public_html/testing/enrolment/thanks.php 中的空查询
我怀疑这与 if/else 语句有关,但不确定实际问题是什么。作为测试,我删除了 if/else 语句并成功地从表单中提交了一些值。不幸的是,当我使它成为条件时,它出现了上述错误。
任何人都可以帮忙吗?
<?php
$firstname = htmlspecialchars(trim($_POST['fname']));
$lastname = htmlspecialchars(trim($_POST['lname']));
$worktel = htmlspecialchars(trim($_POST['worktel']));
$funding = htmlspecialchars(trim($_POST['funding']));
$level = htmlspecialchars(trim($_POST['level']));
$dbc = mysqli_connect('localhost', 'xxxxx', '<xxxx>', 'xxxx')
or die ('Could not connect to MySQL server.');
if ($level != "IOSH Managing Safely"){
if ($funding == "Self Funding"){
$query = "INSERT INTO enrolments (fname, lname, worktel)" .
"VALUES ('$firstname', '$lastname', '$worktel')";
}
else if ($funding == "Employer Funding"){
$query = "INSERT INTO enrolments (fname, lname, worktel)" .
"VALUES ('$firstname', '$lastname', '$worktel')";
}
}
else if ($level == "IOSH Managing Safely"){
if ($funding == "Self Funding"){
$query = "INSERT INTO enrolments (fname, lname, worktel)" .
"VALUES ('$firstname', '$lastname', '$worktel')";
}
else if ($funding == "Employer Funding"){
$query = "INSERT INTO enrolments (fname, lname, worktel)" .
"VALUES ('$firstname', '$lastname', '$worktel')";
}
}
$result = mysqli_query($dbc, $query)
or die ('error querying database');
mysqli_close($dbc);
?>