Code listed below. Everytime I run the query (it's outputting to excel) and I open the excel file, I get only this line in the first field.
Unknown column 'ADP' in 'where clause'
So, it looks like it's passing the companyname value as the column name instead of the value it should be looking for IN the column named companyname. Can someone see why this is happening? Thanks in advance.
<?php require_once('../Connections/spectrum.php'); ?>
<?php
$SSAdv_colors1 = array("#CCCCCC","#FFFFFF");
$SSAdv_k1 = 0;
$SSAdv_m1 = 0;
$SSAdv_change_every1 = 1;
mysql_select_db($database_spectrum, $spectrum);
$query_rs_company = "SELECT DISTINCT(companyname) FROM spec_invoice ORDER BY companyname ASC";
$rs_company = mysql_query($query_rs_company, $spectrum) or die(mysql_error());
$row_rs_company = mysql_fetch_assoc($rs_company);
$totalRows_rs_company = mysql_num_rows($rs_company);
?>
<?
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
if(isset($_POST['ok'])) // submit button pressed
{
$_POST['display'] = trim($_POST['display']);
if($_POST['display'] == '')
{
die("nothing chosen.");
}
else
{
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=$display.xls");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Expires: 0");
$select = "SELECT companyname, invoicenumber, studentfirst, studentlast, coursecode, coursename, startdate, enddate, courselength, sale_price, invoicedate FROM spec_invoice WHERE 'companyname' IN ($display)";
$export = mysql_query($select, $spectrum) or die(mysql_error());
$row = mysql_fetch_assoc($export);
$totalRows = mysql_num_rows($export);
$fields = mysql_num_fields($export);
// BEGIN FOR LOOPING
for ($i = 0; $i < $fields; $i++) {
$header .= mysql_field_name($export, $i) . "\t";
}
while($row = mysql_fetch_row($export)) {
$line = '';
foreach($row as $value) {
if ((!isset($value)) OR ($value == "")) {
$value = "\t";
} else {
$value = str_replace('"', '""', $value);
$value = '"' . $value . '"' . "\t";
}
$line .= $value;
}
$data .= trim($line)."\n";
}
$data = str_replace("\r","",$data);
echo $header."\n".$data;
//IF STATMENT THAT IS PRODUCED IF NO DATA IS PRESENT
if ($data == "") {
$data = "n(0) Records Found!n";
}
die($sql);
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.style3 {font-family: "Lucida Grande CY", Verdana, Tahoma; font-size: 10px; }
-->
</style>
</head>
<body>
<table width="600" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>View online
<form name="form1" id="form1" method="post" action="">
<select name="display" id="display">
<?php
do {
?>
<option value="<?php echo $row_rs_company['companyname']?>"><?php echo $row_rs_company['companyname']?></option>
<?php
} while ($row_rs_company = mysql_fetch_assoc($rs_company));
$rows = mysql_num_rows($rs_company);
if($rows > 0) {
mysql_data_seek($rs_company, 0);
$row_rs_company = mysql_fetch_assoc($rs_company);
}
?>
</select>
<input type="submit" name="ok" value="Submit" />
</form></td>
</tr>
<tr>
<td>Output to Excel </td>
</tr>
</table>
</body>
</html>
<?php
mysql_free_result($rs_company);
?>