很抱歉打扰你这些基本问题。 我收到了一个错误 “您的SQL语法有错误;请查看与您的MySQL服务器版本对应的手册,以便在第10行附近使用正确的语法”。 提前致谢
<?php
$con=mysql_connect("localhost","......","......" );
$database = "......";
$ok = mysql_select_db($database, $con);
mysql_set_charset("UTF8", $con);
$us1 = $_POST['username1'];
$sp1 = $_POST['startPoli1'];
$fp1 = $_POST['finalPoli1'];
$w1 = $_POST['weight1'];
$dD1 = $_POST['depDate1'];
$dT1 = $_POST['depTime1'];
$sql = mysql_query( " SELECT `username1`,`startPoli1`, `finalPoli1`,`weight1` , `depDate1` , `depTime1`, `tilefono1`
FROM customer ,registration1
where ( 'sp1' is null or customer.startPoli1 = 'sp1') and
( 'fp1' is null or customer.finalPoli1 = 'fp1') and
( 'w1' is null or customer.weight1 = 'w1') and
( 'dD1' is null or customer.depDate1 = 'dD1') and
( 'dT1' is null or customer.depTime1 = 'dT1') and
(customer.username1 = registration1.username ");
if($sql === FALSE)
{
die(mysql_error());
}
$results = array();
while($row = mysql_fetch_assoc($sql))
{
$results[] = array(
'username1' => $row['username1'],
'startPoli1' => $row['startPoli1'],
'finalPoli1' => $row['finalPoli1'],
'weight1' => $row['weight1'],
'depDate1' => $row['depDate1'],
'depTime1' => $row['depTime1'],
'tilefono1' => $row['tilefono1']
);
}
echo json_encode(array('select_itin_results' =>$results));
mysql_close($con);
?>
答案 0 :(得分:1)
您在最后一个条件中缺少结束括号。
此(customer.username1 = registration1.username ");
应为:(customer.username1 = registration1.username )");
。
答案 1 :(得分:0)
在SQL
的末尾,您缺少(或者为最后一个条件添加了额外的不必要的圆括号)圆括号这就是你的SQL:
( " SELECT `username1`,`eidosmetaf1`,`startPoli1`, `finalPoli1`,`weight1` , `depDate1` , `depTime1`, `tilefono1`
FROM customer ,registration1
where ( 'sp1' is null or customer.startPoli1 = 'sp1') and
( 'fp1' is null or customer.finalPoli1 = 'fp1') and
( 'w1' is null or customer.weight1 = 'w1') and
( 'dD1' is null or customer.depDate1 = 'dD1') and
( 'dT1' is null or customer.depTime1 = 'dT1') and
(customer.username1 = registration1.username ");
使用
( " SELECT `username1`,`eidosmetaf1`,`startPoli1`, `finalPoli1`,`weight1` , `depDate1` , `depTime1`, `tilefono1`
FROM customer ,registration1
where ( 'sp1' is null or customer.startPoli1 = 'sp1') and
( 'fp1' is null or customer.finalPoli1 = 'fp1') and
( 'w1' is null or customer.weight1 = 'w1') and
( 'dD1' is null or customer.depDate1 = 'dD1') and
( 'dT1' is null or customer.depTime1 = 'dT1') and
customer.username1 = registration1.username ");