Basically the user enters data in a form.
The user enters the client in a textbox and hits submit.
HTML:
<form method="get" action="process_form.php">
<input type="text" name="client" />
<!-- and so on -->
<input type="submit" name="submit" />
</form>
I want to first of all check that the user entered data in client field.
if (isset($_GET['client']) && ($_GET['client'] != ""))
{
// valid data
}
Then want to check if that data is already in the client table.
The code we discussed before will do this:
$find_client = mysql_query("select client from test where client like \"%" . $_GET['client'] . "%\" limit 1");
if (($find_client != null) && (mysql_num_rows($find_client) == 0))
{
mysql_query("insert test (client) values (\"" . $_GET['client'] . "\")");
}
(put that code where I wrote '// valid data')
(Note that checking for matches with text values is often approximate. Unless your text values are actually primary keys, you can't guarantee that they will be unique or that two slightly different values (e.g. 'kevin' and 'Kevin') aren't supposed to be the same. (That was why I originally suggested working with ids).
MySQL provides the LIKE operator to help with this. It does case in-sensitive comparisons of values. You can also insert the '%' wildcard to help make matches more general.)
So is what I'm doing in the code correct??
It looks to me as if you're using $client as the passed value. Presumably you've used parse_url() or seomthing?
Another thing you've done which may cause problems is that you do your MySQL query to check for existing clients before you've checked to make sure the given client name is a valid string.