Hi all,
I have created a webform with numerous textfields, which allows the user to enter data into database table.
How do I ensure that they do not enter the same data twice?
Thanks,
Kevin.
do a simple SELECT query to check to see if what they have entered is already in the database.
Tried this:
// Check if Subfund already in Database if(isset($subfund) && ($subfund != "")) { $check = mysql_query("select subfund_ID from subfund where subfund like %$subfund% LIMIT 1"); if (mysql_num_rows($check) > 0) { echo '<p>Subfund already entered</p><br />'; echo '<p><a href="upload.php">Return</a></p>'; exit; } } else {
But get this error:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/k28775/public_html/mlist/admin/upload/upload2.php on line 109
Why is this??
change this:
$check = mysql_query("select subfund_ID from subfund where subfund like %$subfund% LIMIT 1");
to this:
$check = mysql_query("select subfund_ID from subfund where subfund like %$subfund% LIMIT 1") or exit(mysql_error());
and look at the resulting error
Get this error:
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '%John% LIMIT 1' at line 1
Since its a text string you're querying on, you need to use: '%John%' - single quotes around the search like string.
Nope. No change.
Second part of the problem could be:
... " from subfund where subfund " ...
Kinda odd you have a table named "subfund" and then have a field named "subfund" - do-able I guess, but could this be a bug? Without the table schema, we don't know...
Sorry you were right earlier:
where subfund like '%$subfund%'
Cheers!!