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

Posts: 316
Location: Michigan
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
 
When You Register, These Ads Go Away!
Old 08-16-2005, 09:47 AM
AxE
AxE's Avatar
Skilled Talker

Posts: 62
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, 12:53 PM
fancymoustache's Avatar
Ultra Talker

Posts: 316
Location: Michigan
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, 06:29 PM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Can you show us your whole script and point out line 28?
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';
Scribble Pad MOD for phpBB (aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 08-16-2005, 07:34 PM
AxE
AxE's Avatar
Skilled Talker

Posts: 62
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 12:08 AM.
AxE is offline
Reply With Quote
View Public Profile
 
Old 08-17-2005, 09:40 AM
fancymoustache's Avatar
Ultra Talker

Posts: 316
Location: Michigan
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 09:44 AM.
fancymoustache is offline
Reply With Quote
View Public Profile
 
Old 08-17-2005, 09:24 PM
AxE
AxE's Avatar
Skilled Talker

Posts: 62
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, 09:27 PM
fancymoustache's Avatar
Ultra Talker

Posts: 316
Location: Michigan
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, 09:38 PM
fancymoustache's Avatar
Ultra Talker

Posts: 316
Location: Michigan
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, 09:46 PM
AxE
AxE's Avatar
Skilled Talker

Posts: 62
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, 10:08 PM
fancymoustache's Avatar
Ultra Talker

Posts: 316
Location: Michigan
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-17-2005, 11:34 PM
AxE
AxE's Avatar
Skilled Talker

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

Posts: 1,054
Name: Mike
Location: Mataro, Spain
Maybe it's better to desidn the DB in such a way that 'email' field is set as UNIQUE?
__________________
Free Mobile Phone Themes

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, 10:53 AM
Novice Talker

Posts: 5
Location: Pakistan
I would also create an index before querying a medium sized table with it.
khurram is offline
Reply With Quote
View Public Profile Visit khurram's homepage!
 
Reply     « Reply to Identical SQL rows
 

Thread Tools

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

vB 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 0.17682 seconds with 12 queries