Jump to content


Photo

type missmatch


  • Please log in to reply
9 replies to this topic

#1 Fearpig

Fearpig
  • Members
  • PipPipPip
  • Advanced Member
  • 195 posts

Posted 06 October 2006 - 10:15 AM

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.

$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>";
}

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

"Whats wrong with the cat?" - Mrs Schrödinger

#2 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 06 October 2006 - 10:24 AM

Are you able to display the code for the search form and also the code that's processing the $_POST/GET request before passing the $PartSearch to the SQL statement.

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#3 Fearpig

Fearpig
  • Members
  • PipPipPip
  • Advanced Member
  • 195 posts

Posted 06 October 2006 - 10:37 AM

Hello HuggieBear...

Here's the form to pass the search string on...
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>";

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.
"Whats wrong with the cat?" - Mrs Schrödinger

#4 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 06 October 2006 - 10:48 AM

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

Try changing this:
$sql="SELECT * FROM tbl_parts WHERE Air_Pressure_Switch= $PartsSearch";

To this:
$sql="SELECT * FROM tbl_parts WHERE Air_Pressure_Switch= '$PartsSearch'";


Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#5 Fearpig

Fearpig
  • Members
  • PipPipPip
  • Advanced Member
  • 195 posts

Posted 06 October 2006 - 11:00 AM

Thanks yet again HuggieBear!!

If I had Globals turned off would something like this do the job?:

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

"Whats wrong with the cat?" - Mrs Schrödinger

#6 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 06 October 2006 - 11:05 AM

Yes, that's perfect.

Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#7 Fearpig

Fearpig
  • Members
  • PipPipPip
  • Advanced Member
  • 195 posts

Posted 06 October 2006 - 11:19 AM

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...nents.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.

//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>";

"Whats wrong with the cat?" - Mrs Schrödinger

#8 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 06 October 2006 - 11:27 AM

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


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


Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#9 Fearpig

Fearpig
  • Members
  • PipPipPip
  • Advanced Member
  • 195 posts

Posted 06 October 2006 - 11:33 AM

Thanks Huggie you're a diamond!!
;D
"Whats wrong with the cat?" - Mrs Schrödinger

#10 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 06 October 2006 - 11:34 AM

Anytime, always a pleasure, never a chore!

Huggie  ;D
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users