When using a SQL query I get no errors if the fields selected are "text" fields. If I include a "number" field in the select script I get "Premature end of script headers: c:/php/php.exe" in my error log.

The script works great as long as no numeric fields are in the select line.

Has anyone else had this issue? What should I do to fix it?

$SQL="select Test_Date, SerialNumber, Part, Platform, Machine ";
///the above line works if no number fields are in it. If I put a number filed in it php bombs.

$SQL="$SQL from gagedata";
$SQL="$SQL where Test_Date = '$sent_datetime'";
$SQL="$SQL and";
$SQL="$SQL Machine like '$mach'";

$result=mssql_query($SQL);

/ How many rows were returned ? /
$returned=mssql_num_rows($result);
$returnedc=mssql_num_fields($result);

if ($table =="gagedata")
{
echo("<b>$returned rows found<br /> </b>\n");
echo("<b>$returnedc cols found<br /> From $plant, on $sent_datetime, Machine $mach </b>\n");
echo ("<table align=center border=\"2\" cellpadding=\"5\" cellspacing=\"2\" width='900'>");
$returnedc=$returnedc++;

// Go print out the field names
while($field=mssql_fetch_field($result))
{
echo ("<th> $field->name </th>");
}
echo ("</tr>\n");

	// Now print out the rows
	while($row=mssql_fetch_array($result)) 
		{
		echo("<tr>");
		$i = 0;
		while ($i < $returnedc)
			{
			echo("<td width 900 align=center>".$row[$i]."</td>");
			$i++;
			}
		echo("</tr>"); 
		}
	echo("</table>");
	}
else	{
	print "No Data available... Press browser back button.";
	}

}//end if:eek:

    No the select sting is like this:
    $SQL="select Test_Date, SerialNumber, Part, Platform, Machine ";

    If I change it like this the script gives the error:
    $SQL="select Flatness, Test_Date, SerialNumber, Part, Platform, Machine ";

    The flatness column in the data base is a number field, all other columns are text fields.

      around selecting a numeric or alpha column at all...

      try echoing back the SQL string to look at the line before you execte it to ensure that all quotes are in the correct places

      also if you are going to use LIKE then use the % wildcard chars

      $SQL="$SQL Machine like '%$mach%'";

      if not then just use =

        Echo when the string works shows:

        select Test_Date, SerialNumber, Part, Platform, Machine from gagedata where Test_Date = '8/22/02' and Machine like '0117'

        Echo when the sting does not work show:
        select Flatness, Test_Date, SerialNumber, Part, Platform, Machine from gagedata where Test_Date = '8/22/02' and Machine like '0117'

          Echo when the string works shows:

          select Test_Date, SerialNumber, Part, Platform, Machine from gagedata where Test_Date = '8/22/02' and Machine like '0117'

          Echo when the sting does not work show:
          select Flatness, Test_Date, SerialNumber, Part, Platform, Machine from gagedata where Test_Date = '8/22/02' and Machine like '0117'

            $result=mssql_query($SQL) or die ("error is ".mysql_error());

            to see if there is specific error that is causing a problem

              This gave the same 500 error;

              I noticed that the columns that do not work have data like 0.03336698532

              If I try a column with data like 0.005 this numeric column works.

              Is there a way to select only the first 5 digits of a column?

                $SQL="select Test_Date, SerialNumber, Part, Platform, Machine ";
                ///the above line works if no number fields(or small number of digits in a numeric field) are in it. If I put a number field (that has many digits) in it php bombs.

                $SQL="$SQL from gagedata";
                $SQL="$SQL where Test_Date = '$sent_datetime'";
                $SQL="$SQL and";
                $SQL="$SQL Machine like '$mach'";

                $result=mssql_query($SQL);

                If I use a numeric field and convert it as part of the SQL call it works fine. Example that works::::

                $SQL="select Test_Date, convert(varchar,height) as height, Part, Platform, Machine ";
                // Notice the above converts the SQL data prior to bringing it back from the server. This allows the php mssql software to process it.

                $SQL="$SQL from gagedata";
                $SQL="$SQL where Test_Date = '$sent_datetime'";
                $SQL="$SQL and";
                $SQL="$SQL Machine like '$mach'";

                $result=mssql_query($SQL);

                Thnks for your help.

                I didn't try converting every thing to ODBC but I think that would have worked as well.

                😃

                  Write a Reply...