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 15:18

".:[ ikciu ]:." <no@mail.com> wrote in message
news:eh1edt$9f6$1@news.dialog.net.pl...
> Hmm linda <newsaccount@tiscali.co.uk> wrote:
>> Many, many thanks in advance,
>
>> @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
>
> you no need to escape integer variables - you should to check values
> before insert it in db.
> your question is a bit st.... if your table in db has autoincrement you no
> need to wory about it, just insert new data - do not set id manualy !!!
>
> --
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Ikciu | gg: 718845 | yahoo: ikciu_irsa | www: www.e-irsa.pl
>
> 2be || !2be $this => mysql_query();
Many thanks for your reply ikciu,

I can't set the id's to autoincrement as these products have there own
product id. But some times those who enter the data, don't imput the
correct product id, hence why I wanted to print and error message so user
could go back and correct the product id. I have finaly got it to work as
follows:

[PHP]
<?php
//conection stuff

@mysql_connect($host,$user,$password) or die("Unable to connect to
server!");
@mysql_select_db($database)or die("Unable to connect to database, please try
later!");

$id=mysql_real_escape_string($_POST['id']);
$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 = "SELECT id FROM floral WHERE id='$id'";
$result = mysql_query($query);

if (mysql_num_rows($result)>0) {
include 'error.php';
} else {
$query = "INSERT INTO floral VALUES
('$id','$name','$info','$pic','$lg_pic','$price')";
$result = mysql_query($query);
header("Location: added.php");
}

mysql_close();
?>
[/PHP]

It all works well now ;-) I can see it's going to be a REAL learning curb
with php. I don't think I'm going to be picking it up as fast as I learnt
html and css! sigh....
Best wishes,
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

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