Forum Moderators: coopster
$sql = "SELECT ref FROM log WHERE ref='$ref' REGEXP '^[0-9]'";
$sql = "SELECT FROM log WHERE ref='$ref' REGEXP '^[0-9]'";
$result = mysql_query($sql) or die(mysql_error());
$num_rows = mysql_num_rows($result);
if ($num_rows == 0) {
..INSERT INTO DATABASE
} else {
..ALREADY EXISTS SO WARN THE USER
}
$sql = "SELECT ref FROM log WHERE ref REGEXP '^[0-9]'";
$result = mysql_query($sql) or die(mysql_error());
<form action="#" id="insert_form" method="post" autocomplete="off">
<input type="text" name="ref" />
<input type="text" name="in" />
<input type="text" name="out" />
<input type="submit" value="Submit" />
</form>
// 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 digit
if ( 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
...
}