MortimerJazz Posted January 16, 2007 Share Posted January 16, 2007 Hi there,I'm currently writing a form where a user will input the first three characters of a postcode.In my database I have registered users full postcodes, but when I run my query I only want to match the from the form to the first three letters of the database value.I'm currently using the following query:[code]$sql_postcode_check = mysql_query("SELECT username, postcode FROM users WHERE left(cast(postcode as string), 3) = '$postcode'");[/code]But I'm getting an error message saying that the supplied argument is not a valid MySQL result resource.Can anyone tell me what I'm doing wrong?Thanks Quote Link to comment Share on other sites More sharing options...
paul2463 Posted January 16, 2007 Share Posted January 16, 2007 add an or die at the end of the query and find out why the result resource is not there[code]$sql_postcode_check = mysql_query("SELECT username, postcode FROM users WHERE left(cast(postcode as string), 3) = '$postcode'") or die ('Error in Query ' . mysql_error())[/code] ; Quote Link to comment Share on other sites More sharing options...
MortimerJazz Posted January 16, 2007 Author Share Posted January 16, 2007 Thanks Paul.I'm getting the following error message:[quote]right syntax to use near 'string), 3) = 'SL9'' at line 3[/quote]SL9 is what I typed into the form field. Quote Link to comment Share on other sites More sharing options...
paul2463 Posted January 16, 2007 Share Posted January 16, 2007 it seems it does not like your WHERE statement - try this one then, its worth a go(tested the substring() function on PHPMyAdmin and it works on another table I have with postcodes in it[code]$sql_postcode_check = mysql_query("SELECT username, postcode FROM users WHERE SUBSTRING(postcode,1,3) = '$postcode'") or die ('Error in Query ' . mysql_error())[/code] Quote Link to comment 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.