1

当我的表单被提交(通过 Ajax)时,我收到以下错误消息:

[17-Oct-2012 11:46:29] PHP Warning:  mysqli_query() [<a href='function.mysqli-query'>function.mysqli-query</a>]: Empty query in /home1/xenongro/public_html/testing/enrolment/thanks.php on line 32

我怀疑这与 if/else 语句有关,但不确定实际问题是什么。

任何人都可以帮忙吗?

<?php

$firstname = htmlspecialchars(trim($_POST['fname']));
$lastname = htmlspecialchars(trim($_POST['lname']));
$worktel = htmlspecialchars(trim($_POST['worktel']));

$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);

?>
4

3 回答 3

0

尝试

var_dump($query);
var_dump($funding);

就在之前

$result = mysqli_query($dbc, $query);

它会给你更多信息

我怀疑这$funding可能会对你的常量字符串有轻微的变化

可能是错字/多余的空间/大写字母

于 2012-10-17T10:52:55.880 回答
0

没有设置查询的情况有两种:级别不匹配字符串,或者资金不匹配字符串。可能是空格的问题。

更糟糕的是,您不使用 mysql_real_escape_string,除非打开了 magic_quotes_gpc,否则攻击者可以注入他的 SQL。

于 2012-10-17T10:53:41.190 回答
0

$funding在提供的代码示例中似乎没有定义,因此您if的 ' 都不会匹配。

于 2012-10-17T10:54:38.733 回答