473,387 Members | 1,486 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

MySQL Entry Problem

155 100+
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:



Expand|Select|Wrap|Line Numbers
  1. $cn = $company_name;
  2.  
  3. 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')
  4. {
  5. echo "Registration Denied";
  6. footer();
  7. exit();
  8. }
  9. else
  10. { // 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:

Expand|Select|Wrap|Line Numbers
  1. The banned name could not be updated due to a system error.
  2.  
  3. Duplicate entry '' for key 2
  4.  
  5. Query: INSERT INTO banned VALUES ('', 'Redstar', '')
Here's my add banned name script:

Expand|Select|Wrap|Line Numbers
  1. if (isset($_POST['submitted']))
  2. { // Handle the form.
  3.  
  4. $b_name = escape_data($_POST['b_name']);
  5. $b_email = escape_data($_POST['b_email']);
  6.  
  7. $query = "INSERT INTO banned VALUES ('', '$b_name', '$b_email')";
  8. $result = mysql_query($query);
  9. if (mysql_affected_rows() == 1) { // If it ran OK.
  10.  
  11. // Print a message.
  12. echo "<p>The banned name has been entered.</p>";
  13.  
  14. } else { // If it did not run OK.
  15. echo "<h2>System Error</h2>
  16. <p>The banned name could not be added due to a system error.</p>"; // Public message.
  17. echo "<p>" . mysql_error() . "<br><br>
  18. <strong>Query:</strong> " . $query . "</p>"; // Debugging message.
  19.  
  20. footer(); // Include the HTML footer.
  21. exit();
  22. mysql_close();
  23. }
I have no unique keys set for the banned names table.

Thanks
May 28 '09 #1
10 2009
Markus
6,050 Expert 4TB
What's the table structure? I've never had this error before.
May 28 '09 #2
DavidPr
155 100+
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
May 28 '09 #3
Markus
6,050 Expert 4TB
@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.
May 28 '09 #4
dlite922
1,584 Expert 1GB
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
May 28 '09 #5
Markus
6,050 Expert 4TB
@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.
May 28 '09 #6
dlite922
1,584 Expert 1GB
@Markus
exactly find what is unique about each user and how verifiable is that piece of info.
May 28 '09 #7
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.
Expand|Select|Wrap|Line Numbers
  1. /* Instead of: */
  2. INSERT INTO banned VALUES ('', 'Redstar', '')
  3.  
  4. /* Do: */
  5. INSERT INTO banned(b_name, b_email) VALUES ('Redstar', '')
  6.  
  7. /* This might even work to (can't test it on MySQL 4 atm) */
  8. 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:
Expand|Select|Wrap|Line Numbers
  1. mysql> CREATE TABLE test_cs(
  2.     ->   value varchar(50)
  3.     ->     CHARACTER SET latin1
  4.     ->     COLLATE latin1_general_cs
  5.     -> );
  6. Query OK, 0 rows affected (0.00 sec)
  7.  
  8. mysql> INSERT INTO test_cs(value)
  9.     -> VALUES ('John'), ('john'), ('JOHN');
  10. Query OK, 3 rows affected (0.00 sec)
  11. Records: 3  Duplicates: 0  Warnings: 0
  12.  
  13. mysql> SELECT * FROM test_cs WHERE value = 'john';
  14. +-------+
  15. | value |
  16. +-------+
  17. | john  |
  18. +-------+
  19. 1 row in set (0.00 sec)
Or, if you already have a table that does not specify the collation:
Expand|Select|Wrap|Line Numbers
  1. mysql> SELECT * FROM test_ci WHERE value = 'John';
  2. +-------+
  3. | value |
  4. +-------+
  5. | John  |
  6. | john  |
  7. | JOHN  |
  8. +-------+
  9. 3 rows in set (0.00 sec)
  10.  
  11. mysql> SELECT * FROM test_ci
  12.     -> WHERE value = 'John' COLLATE latin1_general_cs;
  13. +-------+
  14. | value |
  15. +-------+
  16. | John  |
  17. +-------+
  18. 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 ;)
May 28 '09 #8
DavidPr
155 100+
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.
May 28 '09 #9
Markus
6,050 Expert 4TB
@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.

Expand|Select|Wrap|Line Numbers
  1. $string = "A string #*& with _=+ different characters.";
  2. $string = preg_replace('/[^a-zA-Z0-9]/', '', $string);
  3. echo $string;
  4.  
May 28 '09 #10
DavidPr
155 100+
How would you store a modified version of company_name and the actual company_name?
May 28 '09 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

5
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...
7
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...
1
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...
0
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...
0
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...
13
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",...
8
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...
110
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...
2
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...
1
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...
0
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$) { } ...
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
jinu1996
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.