崩溃在哪里上课

时间:2015-02-24 08:39:56

标签: php phpmyadmin

我在“select”语句中使用数组时遇到问题 该数组包含以下字符串 排列 (     [0] => M.A.JINNA     [1] => K.DHANA RAJU     [2] => B.EPHRIM ) 数组数据来自以下数据

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<style>
table{
	border : 1px solid black;
}
tr{
	border : 1px solid black;
}
td{
	border : 1px solid black;
}
</style

<head>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Update Deployement</title>

<style type="text/css">
body
{
   background-color: #00FF00;
   background-image: url(images/gail-india.jpg);
   color: #000000;
   scrollbar-face-color: #0B0B0B;
   scrollbar-arrow-color: #C8C8C8;
   scrollbar-3dlight-color: #0B0B0B;
   scrollbar-darkshadow-color: #000000;
   scrollbar-highlight-color: #141414;
   scrollbar-shadow-color: #060606;
   scrollbar-track-color: #0B0B0B;
}
</style>
</head>


<body>
<form method="post" action="edit_data.php">
<div id="wb_Image3" style="margin:0;padding:0;position:absolute;left:7px;top:4px;width:208px;height:129px;text-align:left;z-index:0;">
<img src="images/image_thumb3.png" id="Image2" alt="" border="0" style="width:208px;height:129px;"></div>

<?php
$con = mysql_connect("localhost","root","");
 if (!$con)
{
  die('Could not connect: ' . mysql_error());
}
mysql_select_db("gail", $con);
$installation_1 = trim($_POST['installation']);
$area_1 = trim($_POST['area']);
$district_1 = trim($_POST['district']);

if(empty($area_1) AND empty($district_1))
{
$sql = "SELECT * FROM deployment WHERE installation ='" . $installation_1 . "'";
}

else if(empty($installation_1) AND empty($district_1))
{
$sql = "SELECT * FROM deployment WHERE area ='" . $area_1 . "'";
}

else if(empty($installation_1) AND empty($area_1))
{
$sql = "SELECT * FROM deployment WHERE district ='" . $district_1 . "'";
}

else if(empty($district_1))
{
$sql = "SELECT * FROM deployment WHERE installation ='" . $installation_1 . "' AND area ='" . $area_1 . "'";
}

else if(empty($area_1))
{
$sql = "SELECT * FROM deployment WHERE installation ='" . $installation_1 . "' AND district ='" . $district_1 . "'";
}


else if(empty($installation_1))
{
$sql = "SELECT * FROM deployment WHERE area ='" . $area_1 . "' AND district ='" . $district_1 . "'";
}

else
{
$sql = "SELECT * FROM deployment WHERE installation ='" . $installation_1 . "' AND area ='" . $area_1 . "' AND district ='" . $district_1 . "'";
}
$result = mysql_query($sql);

echo "<table id='table1' width = '500' align = 'center' style= 'border:1px'>";
	echo "<tr><b>";
		echo "<td>Installation</td>";
		
		echo "<td>Area</td>";

		echo "<td>District</td>";
		
		echo "<td>Employee Name</td>";
                
                echo "<td>Reference</td>";
		
		echo "</b></tr>";
$employee = array();
	
while($row = mysql_fetch_array($result))
	{
		echo "<tr>";
		echo ("<td>$row[installation]</td>"); 
                echo ("<td>$row[area]</td>"); 
                echo ("<td>$row[district]</td>");
                echo ("<td>$row[employeename]</td>");
                echo ("<td>$row[ref]</td>");	
		echo"</tr>";
		$employee[] = $row['employeename'];
		$arrlength = count($employee);	
	}


	echo"</table>";
	echo '<pre>'; print_r(array_filter($employee)); echo '</pre>';
?>
</body>
</html>

现在我收到这样的错误:你的SQL语法有错误;查看与MySQL服务器版本对应的手册,以便在第1行''M.A.JINNA,K.DHANA RAJU,B.EPHRIM'附近使用正确的语法 请提前给我任何建议,谢谢 注意:由于客户要求,我无法使用员工ID而不是员工姓名

代码是

<?
$emp = implode( ',', $employee );
echo '<pre>'; print_r($emp); echo '</pre>';

$sql = "SELECT * FROM securitystaffdetails WHERE employeename IN '" . $emp . "'";
$result = mysql_query($sql) or die(mysql_error());


echo "<table id='table1' width='1500' style= 'border:1px'>";
	echo "<tr><b>";
		echo "<td>Employee Name</td>";
		
		echo "<td>Address</td>";

		echo "<td>DOB</td>";
		
		echo "<td>Age</td>";
                
                echo "<td>SEx</td>";

		echo "<td>Mobile Number</td>";

		echo "<td>Blood Group</td>";

		echo "<td>ID Card</td>";

		echo "<td>Ex Army Idcard</td>";

		echo "<td>Police Clearence</td>";

		echo "<td>ESI Card</td>";

		echo "<td>PF Account</td>";

		echo "<td>PAN Card</td>";

		echo "<td>Voter ID</td>";

		echo "<td>Ration/Family</td>";
		
		echo "</b></tr>";
$employee = array();
	
while($record = mysql_fetch_object($result))
	{
		echo "<tr>";
		echo ("<td>$record[employeename]</td>"); 
                echo ("<td>$record[address]</td>"); 
                echo ("<td>$record[dob]</td>");
                echo ("<td>$record[age]</td>");
                echo ("<td>$record[sex]</td>");
		echo ("<td>$record[mobn]</td>");
		echo ("<td>$record[bg]</td>");
		echo ("<td>$record[icard]</td>");
		echo ("<td>$record[exarmycard]</td>");
		echo ("<td>$record[policeclearence]</td>");
		echo ("<td>$record[esicard]</td>");
		echo ("<td>$record[pfa]</td>");
		echo ("<td>$record[pancard]</td>");
		echo ("<td>$record[acard]</td>");
		echo ("<td>$record[vcard]</td>");
		echo ("<td>$record[rcard]</td>");	
		echo"</tr>";
		
	}

	
	echo"</table>";

?> 

2 个答案:

答案 0 :(得分:1)

将您的内爆线更改为:

$emp = implode( "','", $employee );

并且您的查询是:

"SELECT * FROM securitystaffdetails WHERE employeename IN ('" . $emp . "')";

答案 1 :(得分:0)

你错过了()。

$sql = "SELECT * FROM securitystaffdetails WHERE employeename IN ('" . $emp . "')";