I'm still struggling with this but have had another idea, how about I select all the fields that begin with a number in one sql and then in another check to see if the reference I'm lookinf for exists.

Thats correct. What I'm working on is a cash register log where by when tickets are paid out the user enters the ticket number (reference) and amount on to the log. To prevent people paying out twice I want it to warn if the reference already exists. However I am only interested in references that begin with a number, which means they can enter a reference of say "Expenses" and it not come up with a warning.

// process input from the form, sanitise everything// I'm assuming the value filled in in the ref field goes into $ref in here.

// test if the "ref" from your post starts with a digitif ( preg_match ('/^[0-9]/',$ref) ) { // starts with a digit, lets' see if it can be found already in the database // SELECT ref FROM log WHERE ref='$ref' //perform query and warn user as needed ...} else { // record log ...}