adult.swim Posted October 4, 2006 Share Posted October 4, 2006 I have created a html form page, and a corresponding process page. My form gets input from the user, and compares it to the fields in my database. If the input in the form matches a field in the dB, the process page returns the corresponding record.The problem is only the address input for the form works correctly. All of the other fields return all the records in the dB. I've tried varying the SQL query code many times. My question is why does only the address search work as opposed to the other input fields?search.php: form[code]<form id=\"search\" method=\"post\" action=\"process.php\"><table class=\"search1\"><tr><th><label for=\"pad\">Pad Number</label></th><td><input id=\"pad\" name=\"pad\" type=\"text\" class=\"inputbox\" size=\"50\" /><br /></td></tr><tr><th><label for=\"mls\">MLS Number</label></th><td><input id=\"mls\" name=\"mls\" type=\"text\" class=\"inputbox\" size=\"50\" /><br /></td></tr><tr><th><label for=\"address1\">Address</label></th><td><input id=\"address1\" name=\"address1\" type=\"text\" class=\"inputbox\" size=\"100\" /><br /></td></tr><tr><th><label for=\"city\">City</label></th><td><input id=\"city\" name=\"city\" type=\"text\" class=\"inputbox\" size=\"100\" /><br /></td></tr><tr><th><label for=\"zip\">Zip Code</label></th><td><input id=\"zip\" name=\"zip\" type=\"text\" class=\"inputbox\" size=\"15\" /><br /></td></tr></table><br /><table class=\"search2\"><tr><td><input type=\"Submit\" value=\"Submit\" style=\"width: 60px; font-size: 1.0em; padding: 2px 10px 2px 10px; margin: 5px 3px -3px 3px; background-color: #115492; float: left; border: solid 1px #023666; color: #ffffff; text-decoration: none;\" /><input type=\"Reset\" value=\"Reset\" style=\"width: 60px; font-size: 1.0em; padding: 2px 10px 2px 10px; margin: 5px 3px -3px 3px; background-color: #115492; float: left; border: solid 1px #023666; color: #ffffff; text-decoration: none;\" /><input type=\"hidden\" name=\"op\" value=\"do\" /><p> </p></td></tr></form></table>[/code]---------------------------------------------process.php:[code]<? # connect to a DSN "mydb" with a user and password "marin" $connect = odbc_connect("**", "**", "**");# query the users table for name and surname$query = "SELECT * FROM props WHERE props.MLSnumber='$mls' OR props.Pads LIKE '%$pad%'OR props.Address LIKE '%$address1%'OR props.City='$city'OR props.Zip='$zip'";# perform the query$result = odbc_exec($connect, $query);//output results to standard output //odbc_result_all($result, "BORDER=1"); # fetch the data from the databasewhile(odbc_fetch_row($result)){ $mls = odbc_result($result, 2); $address = odbc_result($result, 5); $pad = odbc_result($result, 16); $city = odbc_result($result, 7); $zip = odbc_result($result, 9); $check = odbc_result($result, 17);// print("$mls $address $pad $city $zip"); //format results print ("<tr>"); print ("<td>$pad</td>"); print ("<td>$mls</td>"); print ("<td>$address</td>"); print ("<td>$city</td>"); print ("<td>$zip</td>"); print ("</tr>"); } # close the connectionodbc_close($connect);?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/22944-sql-query-problems/ Share on other sites More sharing options...
sasa Posted October 5, 2006 Share Posted October 5, 2006 expresion some_field LIKE '%%' is always true Quote Link to comment https://forums.phpfreaks.com/topic/22944-sql-query-problems/#findComment-104582 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.