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 Breklin on 10/17/06 17:54

#1, if you have set your table to auto_increment for the ID field, you
do not need to use a post to put that data into that field. This is a
great way to eliminate the possibility of duplicate ID data.

Remove the $_POST['id'] and in the SQL statement, use '' instead of
'$id' like this:

$query = "INSERT INTO floral VALUES ('','$name','$info','$pic','$lg_pic','$price')";

There are many PHP form validation scripts out there with messaging. Try going to phpclasses.org for these types of scripts.



linda wrote:
> 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();
> ?>
>
>
>

 

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

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