Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Old 08-15-2005, 07:48 PM Identical SQL rows
fancymoustache's Avatar
Ultra Talker

Posts: 316
Location: Michigan
Trades: 0
How would I go about checking a database [with PHP] for identical information before submitting new information. I'm creating a mailing list and I want to make sure people don't submit the same email twice.

Thanks,
Micah
fancymoustache is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-16-2005, 10:47 AM
AxE
AxE's Avatar
Skilled Talker

Posts: 62
Trades: 0
When registering the email, do this:

PHP Code:
$sql "SELECT *
FROM `your_table`
WHERE `email`='"
.$useremail."'";
$sql = @mysql_query($sql);
if(!
$sql){die("MySQL Error! ".mysql_error()); }
$sql = @mysql_fetch_array($sql);
if(!empty(
$sql['email'])){
  die 
"Error, email already in use.";

Theres quite a few things you need to change there though.
- In the query, change the table name to your table name
- In the query, change the `email` column to the correct name.
- $useremail is the value of the email thats about to be submitted. This is the email that we are checking for duplicates of.
- you need to change $sql['emai'] to $sql['whatever_your_email_column_is'];.

If it doesnt work, post the SQL error or Parse error or whatever.
AxE is offline
Reply With Quote
View Public Profile
 
Old 08-16-2005, 01:53 PM
fancymoustache's Avatar
Ultra Talker

Posts: 316
Location: Michigan
Trades: 0
Thank you, AxE. I did get an error, however. You should know I'm not extremely knowledgeable about PHP, so please be patient with me. The error I received was this: "Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in add.php on line 28"
fancymoustache is offline
Reply With Quote
View Public Profile
 
Old 08-16-2005, 07:29 PM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
Can you show us your whole script and point out line 28?
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 08-16-2005, 08:34 PM
AxE
AxE's Avatar
Skilled Talker

Posts: 62
Trades: 0
That error is usually given when you specify a variable inside a string( using the "String " . $var . "String" method) but miss a peroid off somewhere. But, Like 0beron said, can you post the whole code and point out the error line?

Last edited by AxE; 08-17-2005 at 01:08 AM..
AxE is offline
Reply With Quote
View Public Profile
 
Old 08-17-2005, 10:40 AM
fancymoustache's Avatar
Ultra Talker

Posts: 316
Location: Michigan
Trades: 0
I'm sorry. It was kind of stupid of me to assume you could know what my problem is without looking at my code. Anyway, I changed it around some, so I have the same error, only on line 34. Here is what I did:

PHP Code:
$name $HTTP_POST_VARS["input_name"];
$ml_email $HTTP_POST_VARS["input_email"];

if (!
eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$"$ml_email))
{
echo 
"That is not a valid email adress.  Please return to the previous page and try <a href=\"ml.html\">again</a>.";
exit;
} else {
mysql_connect("localhost","user","pass") or die("Error connecting to Database!<br>" mysql_error());
mysql_select_db("rebhedge_DB1") or die("Error selecting Database!<br>" mysql_error());

 
$sql "SELECT *
FROM `ml`
WHERE `email`='"
.$ml_email."'";
$sql = @mysql_query($sql);
if(!
$sql){die("MySQL Error! ".mysql_error()); }
$sql = @mysql_fetch_array($sql);
if(!empty(
$sql['email'])){
/*Line 34*/  die "Error, email already in use.";


Last edited by fancymoustache; 08-17-2005 at 10:44 AM..
fancymoustache is offline
Reply With Quote
View Public Profile
 
Old 08-17-2005, 10:24 PM
AxE
AxE's Avatar
Skilled Talker

Posts: 62
Trades: 0
Die is a function, try die("Error, email already in use");

Sorry about that, my bad.
AxE is offline
Reply With Quote
View Public Profile
 
Old 08-17-2005, 10:27 PM
fancymoustache's Avatar
Ultra Talker

Posts: 316
Location: Michigan
Trades: 0
Thanks, Axe. You've saved my butt in two areas of the same project. I really appreciate you taking the time to do help me out.
__________________
For over a thousand generations, the Jedi Knights were the guardians of peace and justice in the Old Republic. Before the dark times, before the Empire.
fancymoustache is offline
Reply With Quote
View Public Profile
 
Old 08-17-2005, 10:38 PM
fancymoustache's Avatar
Ultra Talker

Posts: 316
Location: Michigan
Trades: 0
Sorry I seem to have run into more problems. I get the error message "Parse error: parse error, unexpected $ in add.php on line 22" when my code is this:
PHP Code:
<?php
$name 
$HTTP_POST_VARS["input_name"];
$ml_email $HTTP_POST_VARS["input_email"];

if (!
eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$"$ml_email))
{
echo 
"That is not a valid email adress.  Please return to the previous page and try <a href=\"ml.html\">again</a>.";
exit;
} else {
mysql_connect("localhost","user","pass") or die("Error connecting to Database!<br>" mysql_error());
mysql_select_db("rebhedge_DB1") or die("Error selecting Database!<br>" mysql_error());

 
$sql "SELECT *
FROM `ml`
WHERE `email`='"
.$ml_email."'";
$sql = @mysql_query($sql);
if(!
$sql){die("MySQL Error! ".mysql_error()); }
$sql = @mysql_fetch_array($sql);
if(!empty(
$sql['email'])){
  die(
"Error, email already in use");
}
/*This being Line 22*/?>
__________________
For over a thousand generations, the Jedi Knights were the guardians of peace and justice in the Old Republic. Before the dark times, before the Empire.
fancymoustache is offline
Reply With Quote
View Public Profile
 
Old 08-17-2005, 10:46 PM
AxE
AxE's Avatar
Skilled Talker

Posts: 62
Trades: 0
You've missed a } off the end. You have Two IF statements there, but only one closed one. Add } on to line 22
AxE is offline
Reply With Quote
View Public Profile
 
Old 08-17-2005, 11:08 PM
fancymoustache's Avatar
Ultra Talker

Posts: 316
Location: Michigan
Trades: 0
AxE, you're my hero. I really appreciate your help!
__________________
For over a thousand generations, the Jedi Knights were the guardians of peace and justice in the Old Republic. Before the dark times, before the Empire.
fancymoustache is offline
Reply With Quote
View Public Profile
 
Old 08-18-2005, 12:34 AM
AxE
AxE's Avatar
Skilled Talker

Posts: 62
Trades: 0
Glad I could help
AxE is offline
Reply With Quote
View Public Profile
 
Old 08-18-2005, 11:28 AM
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
Maybe it's better to desidn the DB in such a way that 'email' field is set as UNIQUE?
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 08-18-2005, 11:53 AM
Novice Talker

Posts: 5
Location: Pakistan
Trades: 0
I would also create an index before querying a medium sized table with it.
__________________

Please login or register to view this content. Registration is FREE



Please login or register to view this content. Registration is FREE
khurram is offline
Reply With Quote
View Public Profile Visit khurram's homepage!
 
Reply     « Reply to Identical SQL rows
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.33783 seconds with 12 queries