|
Posted by Breklin on 10/18/06 17:53
Linda,
Please don't count me in on that BS Steve and the other guy were
spewing. I don't buy into it. I am just hear to help you.
Regarding the use of auto_increment for a record ID, or lack thereof, I
would still recommend it to insure that you do get a duplicate primary
id for the table. Since you said someone would be inputting the product
code from the supplier, you can simply create a secondary id field for
the alphanumeric code you will be using for your products. Then, using
the query example I showed you, you can check for duplicate product ids
and return an error that way.
It is the most simple way to get you up and running at this point. Once
you have it going, you can always sharpen your teeth on it as you get
more advanced in your PHP skills. I was simply trying not to overwhelm
you with complicated scripting.
Best of luck to you.
Breklin
linda wrote:
> "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]
|