You are here: Re: on input form showing error message for duplicate entry. « All PHP « IT news, forums, messages
Re: on input form showing error message for duplicate entry.

Posted by linda on 10/17/06 23:26

"linda" <newsaccount@tiscali.co.uk> wrote in message
news:4533f42a$1_2@mk-nntp-2.news.uk.tiscali.com...
>I very new to php could someone please explain how to write an error
>message into my AddNew.php below. id is set to unique so at the moment if
>someone adds a product and the id is already in the database, it just
>doesn't enter anything. Ideally I would like to display an error message,
>with a back button to correct the id.
>
> So far I've tried running a SELECT query with an if statement prior to
> the INSERT but I just don't know enough php to get this to work. I would
> be very greatful for any info and advice from those in this newsgroup.
>
> Many, many thanks in advance,
> Linda
>
>
> [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!");
>
> $id=mysql_real_escape_string($_POST['id']); //This is set to unique
> $name=mysql_real_escape_string($_POST['name']);
> $info=mysql_real_escape_string($_POST['info']);
> $pic=mysql_real_escape_string($_POST['pic']);
> $lg_pic=mysql_real_escape_string($_POST['lg_pic']);
> $price=mysql_real_escape_string($_POST['price']);
>
> $query = "INSERT INTO floral VALUES
> ('$id','$name','$info','$pic','$lg_pic','$price')";
> mysql_query($query);
> header("Location: added.php");
>
> mysql_close();
> ?>
>

Guys I didn't realise that my question would cause so many problems! Steve,
Breklin & "Ikciu", even though I may not be on par with you just yet, and
there fore my question may seem a trifle stupid ;-), I assure you I'm like
a blood hound when it comes to learning something new, so I intend to not
hold that title for very long.

I am very grateful for you useful comments, suggestions and examples of
code. Truly I am! I have downloaded and kept all suggestions in my review
codes folder. And will be spending the week end dissecting and working out
what does what, how and why. But please don't argue any more. I feel
awful that I've been the cause of such discourse. The newsgroup seemed
quite peaceful until I came along.

So just to clarify everything, so there is no more misunderstanding, the
reasons for wanting error reporting on duplicate entries are as follows.

a) The product code is the ID, this is beyond my control as the products
come from the supplier with these codes on. Yes I realise I could have set
id to auto_increment, and then have another field for the product code, but
I thought that as certain products HAVE TO HAVE a unique code it would be
just a waste having an id field with auto_increment. Besides which it would
be the product code that would be used for searching the data base, so i
decided this would be set to primary and unique.

b) The reason for needing error reporting on duplicate entries is due to the
fact that I CAN'T have two or more product codes with the same id. But I
also wanted the person inputting the data to realise that, the product code
they entered already existed, (a wake up and smell the coffee moment) so go
back and correct this!

That's it pure and simple!

I might like to add, I do have tables in the database that use id with
auto_increment, WHERE there is not set product code needed.

Thank you all for the great advice, past midnight now here in the UK, so
must hit the sack!

I will undoubtedly be back with more questions at some point.
Kindest regards,
Linda

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация