Fearpig Posted October 6, 2006 Share Posted October 6, 2006 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 45Error in SQLCan anyone suggest a solution? Cheers Tom Link to comment https://forums.phpfreaks.com/topic/23162-type-missmatch/ Share on other sites More sharing options...
HuggieBear Posted October 6, 2006 Share Posted October 6, 2006 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.RegardsHuggie Link to comment https://forums.phpfreaks.com/topic/23162-type-missmatch/#findComment-104888 Share on other sites More sharing options...
Fearpig Posted October 6, 2006 Author Share Posted October 6, 2006 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 https://forums.phpfreaks.com/topic/23162-type-missmatch/#findComment-104895 Share on other sites More sharing options...
HuggieBear Posted October 6, 2006 Share Posted October 6, 2006 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]RegardsHuggie Link to comment https://forums.phpfreaks.com/topic/23162-type-missmatch/#findComment-104901 Share on other sites More sharing options...
Fearpig Posted October 6, 2006 Author Share Posted October 6, 2006 Thanks yet again HuggieBear!!If I had Globals turned off would something like this do the job?:[code]//Use ID=2 if no id presentif (!isset($_GET['id'])){ $id = "2";}[/code] Link to comment https://forums.phpfreaks.com/topic/23162-type-missmatch/#findComment-104913 Share on other sites More sharing options...
HuggieBear Posted October 6, 2006 Share Posted October 6, 2006 Yes, that's perfect.Huggie Link to comment https://forums.phpfreaks.com/topic/23162-type-missmatch/#findComment-104918 Share on other sites More sharing options...
Fearpig Posted October 6, 2006 Author Share Posted October 6, 2006 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 workingThe address in the browser address bar shows:http://fer-post/test/Spares/List_Boiler_Components.php?id=19So 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 36Here'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 presentif (!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 https://forums.phpfreaks.com/topic/23162-type-missmatch/#findComment-104929 Share on other sites More sharing options...
HuggieBear Posted October 6, 2006 Share Posted October 6, 2006 Try changing this:[code=php:0]//Use ID=2 if no id presentif (!isset($_GET['id'])){ $id = "2";}[/code]To this:[code=php:0]//Use ID=2 if no id presentif (!isset($_GET['id'])){ $id = "2";}else { $id = $_GET['id'];}[/code]RegardsHuggie Link to comment https://forums.phpfreaks.com/topic/23162-type-missmatch/#findComment-104934 Share on other sites More sharing options...
Fearpig Posted October 6, 2006 Author Share Posted October 6, 2006 Thanks Huggie you're a diamond!! ;D Link to comment https://forums.phpfreaks.com/topic/23162-type-missmatch/#findComment-104942 Share on other sites More sharing options...
HuggieBear Posted October 6, 2006 Share Posted October 6, 2006 Anytime, always a pleasure, never a chore!Huggie ;D Link to comment https://forums.phpfreaks.com/topic/23162-type-missmatch/#findComment-104943 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.