|
Posted by .:[ ikciu ]:. on 10/17/06 23:57
Hmm linda <newsaccount@tiscali.co.uk> wrote:
> 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.
make same form for for update and insert
$whatAction = array(1=>'add', 2=>'edit');
if this is edit then you should to get data from db
if this is insert then you user will fill form (you can use js or WF2 for
user side validate) after submit
you have to validate all values, then if there is error show info, otherwise
add your post data to session
make redirection to other php file where you will insert / update it in db
(in this case this is not important because there is no way to add same
value to db, but any way you can do it in right way)
in other file you will just make correct db data (mysql_real_escape_string
for string fields) and you will do insert or update dependent of value
$whatAction which you will store in session too if you will do insert and
you will have1062 error it means the id is taken - then back to previous
file, show typed data in fileds and ask user for retype ID do it until you
will have no error
if it is update then np, just do it
remeber after each db operation you should to check result - there can be
few case when someting will go wrong,
at the and unset session variables and it is done
if you use code ID as a primary key, then there is no reason to set same
value for this field
so just do insert if your mysql_query will return you error code 1062 it
means the id is taken
and user should to type new value for this field - show him info
if you know this is edit just use update
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Ikciu | gg: 718845 | yahoo: ikciu_irsa | www: www.e-irsa.pl
2be || !2be $this => mysql_query();
Navigation:
[Reply to this message]
|