error checks on data entry into mysql from php forms

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
ananth_ak
Forum Newbie
Posts: 23
Joined: Wed Feb 09, 2005 12:42 pm
Location: uk, london
Contact:

error checks on data entry into mysql from php forms

Post by ananth_ak »

Hello,

how do create an error statement if the primary key entered into mysql from a php form is already in the mysql table?

how do you do the same check to ensure user enteres a interger?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Something like

Code: Select all

$query = "INSERT INTO `table` IF NOT EXISTS (`id`) VALUES ('$value')";
if (mysql_query($query)) {
    echo 'Data added to DB';
} else {
    echo 'The data could not be added as this value has already been used in the database';
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

is_numeric() for the second part of your "question"
ananth_ak
Forum Newbie
Posts: 23
Joined: Wed Feb 09, 2005 12:42 pm
Location: uk, london
Contact:

Post by ananth_ak »

thanks for you help!
Post Reply