Skip to main content
Inspiring
February 4, 2007
Question

Duplicate ebtries

  • February 4, 2007
  • 2 replies
  • 296 views
Hi guys,

I want to stop duplicate entries into a mysql database. But, I only want to
stop the entry if TWO of the fields are a duplication.

eg i dont want to allow a name and email address to be the same as already
entered. But, either the name or email address can be the same.

Can anyone help please?

Thanks


This topic has been closed for replies.

2 replies

Inspiring
February 5, 2007
erm...ok, I'm gonna struggle a bit!!

But hey thanks for the help, I will master it somehow!!!!


"David Powers" <david@example.com> wrote in message
news:eq4us7$o46$1@forums.macromedia.com...
> ghoti1 wrote:
>> I want to stop duplicate entries into a mysql database. But, I only want
>> to stop the entry if TWO of the fields are a duplication.
>>
>> eg i dont want to allow a name and email address to be the same as
>> already entered. But, either the name or email address can be the same.
>
> This is quite easy, but involves moving a little code around in Code view.
>
> In your insert page, create a recordset to query the database. Use the
> Advanced recordset dialog box to create a SQL query like this:
>
> SELECT * FROM myTable
> WHERE name = var1
> AND email = var2
>
> Click the plus button in the Variables field to create the variables var1
> and var2. Set the runtime value of the first to $_POST['name'] and the
> second one to $_POST['email'] (amend the names to match the names you have
> given the name and email fields in the insert form). Click OK to close the
> Recordset dialog box.
>
> Dreamweaver always creates the recordset code immediately above the
> DOCTYPE. You need to move all of the recordset code above the code that
> inserts the record in the database. Then wrap the insert record code in a
> conditional statement like this:
>
> if ($totalRows_recordsetName == 0) {
> // insert code goes here
> }
> else {
> // code to alert user that the action has been cancelled
> }
>
> If you have a reasonable amount of experience with PHP, it's quite simple
> to do. If you rely on Dreamweaver to handle all the code, you might
> struggle a bit.
>
> --
> David Powers, Adobe Community Expert
> Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
> Author, "PHP Solutions" (friends of ED)
> http://foundationphp.com/


Inspiring
February 4, 2007
ghoti1 wrote:
> I want to stop duplicate entries into a mysql database. But, I only want to
> stop the entry if TWO of the fields are a duplication.
>
> eg i dont want to allow a name and email address to be the same as already
> entered. But, either the name or email address can be the same.

This is quite easy, but involves moving a little code around in Code view.

In your insert page, create a recordset to query the database. Use the
Advanced recordset dialog box to create a SQL query like this:

SELECT * FROM myTable
WHERE name = var1
AND email = var2

Click the plus button in the Variables field to create the variables
var1 and var2. Set the runtime value of the first to $_POST['name'] and
the second one to $_POST['email'] (amend the names to match the names
you have given the name and email fields in the insert form). Click OK
to close the Recordset dialog box.

Dreamweaver always creates the recordset code immediately above the
DOCTYPE. You need to move all of the recordset code above the code that
inserts the record in the database. Then wrap the insert record code in
a conditional statement like this:

if ($totalRows_recordsetName == 0) {
// insert code goes here
}
else {
// code to alert user that the action has been cancelled
}

If you have a reasonable amount of experience with PHP, it's quite
simple to do. If you rely on Dreamweaver to handle all the code, you
might struggle a bit.

--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/