Page 1 of 1

error checks on data entry into mysql from php forms

Posted: Wed Feb 16, 2005 4:53 am
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?

Posted: Wed Feb 16, 2005 7:28 am
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';

Posted: Wed Feb 16, 2005 9:05 am
by feyd
is_numeric() for the second part of your "question"

Posted: Wed Feb 16, 2005 9:16 am
by ananth_ak
thanks for you help!