Re: on input form showing error message for duplicate entry.



Steve, If you know so much, why don't just help her?? Jesus. However,
thank you. You taught me something I can take with me about the
ID/Auto_increment deal. Much appreciated.

Linda,

Run a select statement using some identifiable value in your form to
check for duplicates. Perhaps the Name of the item or your product code,
etc.

Using that, you can see if any rows were returned. If not, then you can
proceed with your insert query.

See example:
_______________________________________________________
$is_error_exists = false;

$product_id = htmlspecialchars($_POST['product_id_field'])

$query = "SELECT product_id, name
FROM table_name
WHERE product_id = $product_id";

$result = mysql_query($query);

$numrows = mysql_num_rows($result);

if($numrows == 0)
// Execute insert query here
else
$is_error_exists = true;

if($is_error_exists)
echo "There is a record for this product already in the database.";

___________________________________________________________

Now, if Steve has any better ideas to help you instead of nit-picking my
code in lieu of his preference, please allow him to take it away! ;)

There are many ways to do things, Linda. Just find your own special way
and learn to develop it into a clean style along the way.

I personally use MYSQL wrapper classes to execute my queries. They are
very neat and don't clutter your code. You agree, Stevo?

Steve wrote:
"Breklin" <breklin@xxxxxxxxxxxxx> wrote in message
news:vtaZg.632$T_1.76@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
| Linda,
|
| This is how I would write that:
|
| [php]
| <?php
|
| //login details
|
|
| @mysql_connect($host,$user,$password)
| or die("Unable to connect with server!");
| @mysql_select_db($database)
| or die("Unable to connect database, please try later!");
|
| -- No need for a form set ID value. Use the Auto-Increment feature in
MySQL
| -- I have never used the mysql_real_escape_string function. A variation is
below.
|
| // Set Form Data into PHP Vars and format against injection attack
| $name = htmlspecialchars($_POST['name']);
| $info = htmlspecialchars($_POST['info']);
| $pic = htmlspecialchars($_POST['pic']);
| $lg_pic = htmlspecialchars($_POST['lg_pic']);
|
| -- QUESTION: What data time is 'Price': int, varchar, float, etc?
|
| $price = htmlspecialchars($_POST['price']);
|
| -- When using this type of insert, you must make sure you are placing data
values in every field of the table. If you are not listing even one
field in the VALUES portion of the query, you will get a query error.
|
| $query = "INSERT INTO floral VALUES
('','$name','$info','$pic','$lg_pic','$price')";


NOT true. (but not to be too picky)

INSERT INTO florals
(
name ,
info ,
pic ,
lg_pic ,
price
)
VALUES
(
'$name' ,
'$info' ,
'$pic, ,
'$lg_pic' ,
'$price'
)

will insert just fine without having to put '' for the id. PLUS it is *bad*
form to have any sql statement on one line (my opinion). AND (common
opinion), all inserts and selects should *always* list the columns being
updated. the above sql is much more manageable than the latter...you can see
exactly what columns are being used and their associated php variables at a
glance.

i have to say though, either way, this does not address her
problem/question. how does she detect the insertion of DUPLICATE data and if
duplicated, how does she display an error to that effect to the user?



.



Relevant Pages

  • RE: Checking for duplicates.
    ... Thanks for the respnse Steve, I will definitely check this out. ... > Duplicates query Wizard". ... > for finding duplicates - enough to get you started. ... >> would type in the info and would see a pop-up box saying this is a duplicate ...
    (microsoft.public.access.modulesdaovba)
  • RE: Filtering a subform using many combo boxes
    ... "Steve Sanford" wrote: ... SELECT AssignedPriority, AssignedPriorityDetail FROM tblAssignedPriority ... I followed you instructions to the letter and every one of the criteria ... open the query "qryProjects" in design view. ...
    (microsoft.public.access.forms)
  • Re: Deleting duplicate records/same table
    ... append the tblUniqueRecords fields into the fields on tblMaster. ... The new table without the duplicates is called ... Prepared By is the type of query I was ...
    (microsoft.public.access.queries)
  • Re: Query to delete duplicate records - but NOT original
    ... > unique records - I've already got an update query to grab the unique ... > hsc but one other field different - it ignores those 2. ... but this method of removing duplicates requires it. ... >> Access Database Samples: www.rogersaccesslibrary.com ...
    (microsoft.public.access.queries)
  • RE: Want to edit a table based on a query of a query of several qu
    ... First create union query like this -- ... Use that query in design view and add all of the other nine tables. ... This puts all the data in to a single query output without duplicates. ... Then I run a big query of all 9 queries to consolidate the data into one big ...
    (microsoft.public.access.queries)