Jump to content

type missmatch


Fearpig

Recommended Posts

Hi Guys,
Could someone have a quick look at this for me....
There seems to be an error in matching the field types in my query. I am tying to match a variable entered by a user into a text box ($PartsSearch) with a field on an SQL server (Air_Pressure_Switch - data type "ntext"). Here is the code I am using followed by the error message I recieve.

[code]
$conn=odbc_connect('Intranet','sa','password');
if (!$conn)
  {exit("Connection Failed: " . $conn);}

echo "<p class='Body2'>This part may be used with the following boilers:</p>";

$sql="SELECT * FROM tbl_parts WHERE Air_Pressure_Switch=$PartsSearch";
$result=odbc_exec($conn,$sql);
  if (!$result)
    {exit("Error in SQL");}

while (odbc_fetch_row($result))
{
          $Model=odbc_result($result,"Model");
  echo "<b class='Body2'>$Model</b><br>";
}
[/code]

Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC SQL Server Driver][SQL Server]Operand type clash: ntext is incompatible with int, SQL state 22005 in SQLExecDirect in D:\Intranet v3\TEST\Spares\Match_Parts.php on line 45
Error in SQL

Can anyone suggest a solution?
Cheers
Tom
Link to comment
Share on other sites

Hello HuggieBear...

Here's the form to pass the search string on...
[code]echo "<table width=450 border='1'> ";
echo "<tr><td width='428' bgcolor='#CCCCCC' class='Body2'><strong>Match part number to boilers.</strong></td></tr>";
echo "<tr align='center'><td class='Body2'>";

echo "<P align=left class='Body2'></P>";
echo "<form method='GET' action='Match_Parts.php'>";
echo "<input type=text name='PartsSearch' maxlength=255>";
echo "<input type=submit  value='Submit'>";
echo "</form>";
echo "</td></tr></table>";[/code]

I don't have any code that processes the GET, I'm converting it from a MySQL page where it worked without one.
I hope thats enough info for you.
Link to comment
Share on other sites

OK, I'm assuming that no processing means you have globals turned on...

Try changing this:
[code=php:0]$sql="SELECT * FROM tbl_parts WHERE Air_Pressure_Switch= $PartsSearch";[/code]

To this:
[code=php:0]$sql="SELECT * FROM tbl_parts WHERE Air_Pressure_Switch= '$PartsSearch'";[/code]


Regards
Huggie
Link to comment
Share on other sites

OK.... I thought I had Globals turned off, so I've gone back and turned them off now but one of my pages has stopped working

The address in the browser address bar shows:

http://fer-post/test/Spares/List_Boiler_Components.php?id=19

So the id variable is being passed from the page before but I'm getting the error message:

Notice: Undefined variable: id in D:\Intranet v3\TEST\Spares\List_Boiler_Components.php on line 36

Here's the script I'm using, can you see any errors in this one?
Thanks again for all your help.

[code]
//Use ID=2 if no id present
if (!isset($_GET['id'])){
  $id = "2";
}


$sql2="SELECT * FROM tbl_parts WHERE ID='$id'";
$result2=odbc_exec($conn,$sql2);
  if (!$result2)
    {exit("Error in SQL");}


$Model2=odbc_result($result2,"Model"); 
echo "<span class='Body2'><b>Current Boiler Model: $Model2";
echo "</b></span>";

echo "<br><br><table width='350' class='Body2' border=1 cellspacing='0'>\n";

echo "<tr bgcolor=#CCCCCC><td width='200' align='center'><b>Description</b></td><td width='150' align='center'><b>Part No.</b></td></tr>\n";

$Air_Pressure_Switch=odbc_result($result2,"Air_Pressure_Switch"); 
echo "<tr><td>Air Pressure Switch</td><td>$Air_Pressure_Switch</td></tr>\n";

echo "</Table>";[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.