I'm having a problem putting entries into a table.
I have a job board and I want to prevent certain companies from being able to register - again. I don't allow certain type ads, so when they register the first time and I delete them they just re-register and this process goes on and on and on.
I put a piece of code into the registration form that checks to see if if this company is in a list and if so a message is returned saying "registration denied". Only problem with this is that I have to open the page and hard code the company name into the script.
What these people will do is to change the name slightly and they're allowed to re-register, for instance: Company name: Redstar, Company name: RedStar, Company name: Red-star, Company name: Red-Star, and on and on and on.
Here's what I have right now: - $cn = $company_name;
-
-
if ($cn == 'REDSTAR' OR $cn == 'Redstar' OR $cn == 'RedStar' OR $cn == 'Red-star' OR $cn == 'Red-Star' OR $cn == 'Spectrum' OR $cn == 'Pre Paid Legal Services Inc' OR $cn == 'Typeinternational' OR $cn == 'Ozwebresources' OR $cn == 'HOME WORK' OR $cn == 'Advantage Marketing' OR $cn == 'Moms Work Smarter' OR $cn == 'Satisfaction Services' OR $cn == 'Ameriplan' OR $cn == 'ozwebresources' OR $cn == 'OzWebresources' OR $cn == 'OzWebResources' OR $cn == 'ozwebResources' OR $cn == 'Grindhouse Associate' OR $cn == 'John H Maxson')
-
{
-
echo "Registration Denied";
-
footer();
-
exit();
-
}
-
else
-
{ // continue with registration
So what I'm trying to do now is to build a "banned names" database that when the registration page is submitted the first this it does it check to see if the $company_name matches a name on file in the "banned names" table. If so the registration stops and a registration denied message is delivered.
The problem is that MySQL isn't allowing different versions of the same name to be entered. See the different variations of the same name above where a different letter in the company name will be capitalized? When I try to enter in a different variation of the same name I get this message: - The banned name could not be updated due to a system error.
-
-
Duplicate entry '' for key 2
-
-
Query: INSERT INTO banned VALUES ('', 'Redstar', '')
Here's my add banned name script: - if (isset($_POST['submitted']))
-
{ // Handle the form.
-
-
$b_name = escape_data($_POST['b_name']);
-
$b_email = escape_data($_POST['b_email']);
-
-
$query = "INSERT INTO banned VALUES ('', '$b_name', '$b_email')";
-
$result = mysql_query($query);
-
if (mysql_affected_rows() == 1) { // If it ran OK.
-
-
// Print a message.
-
echo "<p>The banned name has been entered.</p>";
-
-
} else { // If it did not run OK.
-
echo "<h2>System Error</h2>
-
<p>The banned name could not be added due to a system error.</p>"; // Public message.
-
echo "<p>" . mysql_error() . "<br><br>
-
<strong>Query:</strong> " . $query . "</p>"; // Debugging message.
-
-
footer(); // Include the HTML footer.
-
exit();
-
mysql_close();
-
}
I have no unique keys set for the banned names table.
Thanks
10 2009
What's the table structure? I've never had this error before.
MySQL version: 4.1.20
Field Type Null Extra
id int(11) No auto_increment
b_name varchar(60) No
b_email varchar(55) No
Keyname Type Cardinality Field
PRIMARY PRIMARY 2 id
@DavidPr
I did some research and it looks like the value for your A.I field is too large for it's data type. Try changing it to BIGINT.
The easiest way is to create a function that will stabilize the name (ie take all non-alphanumeric characters out, including spaces?) , convert to lowercase, THEN put this in your MySQL database. So that after plugging in all those "Red-Star" variations in, the function always outputs "redstar", and this will have only one record in the table instead of 10.
I'm curious,
can't the company make up just ANY name, instead of redStar can't they call it "LASkskf93skdfh" ??
Cheers,
Dan
@dlite922
Good point. You could track IP addresses, also, but they, too, are not reliable.
I imagine, for there to be rhyme & reason to them signing up so incessantly, you must provide something that benefits them, e.g. a 'website' link-back. If so, maybe you can track what value a new signee (not a word, I know) gives.
@Markus
exactly find what is unique about each user and how verifiable is that piece of info.
Atli 5,058
Expert 4TB
Hi.
You shouldn't provide a value for a auto_increment field.
It's best to just leave them out of the query.
If you absolutely must include it, at least use NULL instead of an empty string. - /* Instead of: */
-
INSERT INTO banned VALUES ('', 'Redstar', '')
-
-
/* Do: */
-
INSERT INTO banned(b_name, b_email) VALUES ('Redstar', '')
-
-
/* This might even work to (can't test it on MySQL 4 atm) */
-
INSERT INTO banned VALUES (NULL, 'Redstar', '')
As for the case-sensitive search... you will have to specify a collation, either when you create the table, or in your SELECT query.
Like: - mysql> CREATE TABLE test_cs(
-
-> value varchar(50)
-
-> CHARACTER SET latin1
-
-> COLLATE latin1_general_cs
-
-> );
-
Query OK, 0 rows affected (0.00 sec)
-
-
mysql> INSERT INTO test_cs(value)
-
-> VALUES ('John'), ('john'), ('JOHN');
-
Query OK, 3 rows affected (0.00 sec)
-
Records: 3 Duplicates: 0 Warnings: 0
-
-
mysql> SELECT * FROM test_cs WHERE value = 'john';
-
+-------+
-
| value |
-
+-------+
-
| john |
-
+-------+
-
1 row in set (0.00 sec)
Or, if you already have a table that does not specify the collation: - mysql> SELECT * FROM test_ci WHERE value = 'John';
-
+-------+
-
| value |
-
+-------+
-
| John |
-
| john |
-
| JOHN |
-
+-------+
-
3 rows in set (0.00 sec)
-
-
mysql> SELECT * FROM test_ci
-
-> WHERE value = 'John' COLLATE latin1_general_cs;
-
+-------+
-
| value |
-
+-------+
-
| John |
-
+-------+
-
1 row in set (0.00 sec)
Check out 9.1. Character Set Support in the manual for more info on that.
P.S.
I don't have MySQL 4 to test this on, but this does work on MySQL 5.
P.P.S.
You really really should upgrade to MySQL 5 ;)
The table must automatically create or assign a Collation because I never do. It's currently set to latin1_swedish_ci
The only advantage to my job board is that it's free to use. I use htmlspecialchars, so a link in the ad will not be a link. But they don't know that.
The Company Name will show up in their ad if they don't choose to display "National or Local Company". But no, there's nothing stopping them from using a jumbled up name. I'd delete it and their ad for doing so, but that would be after the fact.
I think what it is that makes these people so persistent is anger. Even though I tell them two, three times before they can place an ad that I do not allow certain type of job ads and if they post one I'm going to remove it. Some try it and I remove it and that's that. But some people just can't let go, they keep posting out of spite to try and annoy me I guess.
I probably would charge a little something to place an ad, but that's over my head.
I didn't think about it, but I don't really need an "id" field. I didn't think about removing all spaces and convert the name to all lower case letters. I know how to change to lower case, but I'll have to read up on how to eliminate spaces and hash marks, etc. Good suggestions. Thanks!
EDIT--
I was just thinking about removing all spaces, hash marks, etc. and changing the company name to all lower case letters to check against banned words. Since they may want to include their company name in their ad, and because I like to have it for my files, I really couldn't modify the company name. Not unless you could do this for checking purposes and if it passes put the company name back to the way it was originally.
@DavidPr
Store an edited version of the company name along with it's original.
You can remove everything but alpha-numeric via a preg_replace. -
$string = "A string #*& with _=+ different characters.";
-
$string = preg_replace('/[^a-zA-Z0-9]/', '', $string);
-
echo $string;
-
How would you store a modified version of company_name and the actual company_name?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Dariusz |
last post by:
I have PHP code (below) which reads data from a MySQL format database. The
problem I am having is trying to find out when the last ID entry was made.
When the script is executed, the $gbID is...
|
by: Jim |
last post by:
I'm using PHP & MySQL to create a simple guestbook. I've created my
table and I'm able to load my information in as usual. I would like it
to display the latest entry first though. I set an id...
|
by: Marcus |
last post by:
Hello, quick question about MySQL storing NULL values...
Say I have a textbox called $_POST and a variable $var.
if(empty($_POST))
$var = NULL;
else
$var = $_POST;
Disregarding...
|
by: Lenz Grimmer |
last post by:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi,
MySQL 4.0.14, a new version of the popular Open Source/Free Software
Database, has been released. It is now available in source and binary...
|
by: Mike Chirico |
last post by:
Interesting Things to Know about MySQL
Mike Chirico (mchirico@users.sourceforge.net)
Copyright (GPU Free Documentation License) 2004
Last Updated: Mon Jun 7 10:37:28 EDT 2004
The latest...
|
by: miker2 |
last post by:
HI,
I'm having trouble writing to a MySql db using python and the MySQLdb
module. Here is the code:
import MySQLdb
base = MySQLdb.connect(host="localhost", user="blah", passwd="blah",...
|
by: Schmalz |
last post by:
Hi all. Probably not an original posting but I have searched high and low
for a satisfactory resolution to this problem. I am using Windows XP, IIS
5.1, PHP 5.1.4 and MySQL 5.0.23 and Dreamweaver...
|
by: alf |
last post by:
Hi,
is it possible that due to OS crash or mysql itself crash or some e.g.
SCSI failure to lose all the data stored in the table (let's say million
of 1KB rows). In other words what is the worst...
|
by: Troy Piggins |
last post by:
We have some php pages on our intranet at work that have been working
fine for years. As a result, they rarely get edited.
The page I'm having trouble with is a timesheet entry page which
uses...
|
by: chanshaw |
last post by:
Alright so I got php running and installed i have mysql running and installed the thing im having a hard time with is having the php to call information from the mysql database. Im on Windows Vista...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |