0

I'm still quite new to php and js and i know how to check if the input field is empty but i dont know how i would check if the value that the user has inputted into the field does not exist in the database ive tried using the == false but to no avail

any help is appreciated!

if (empty($a))
{
    // Error Message
}
if ( $a == false)
{

}
dhilt
  • 18,707
  • 8
  • 70
  • 85
Fabinho
  • 9
  • 2

3 Answers3

0

You need to use an sql query. Personally, I use mysqli extension which has a pretty good and detailed manual. If you are starting to mess with sql queries and user submitted data, you should also check how to escape these queries or even better prepared statements, to avoid sql injections.

Good Luck.

gatas
  • 51
  • 3
0

Store the input value in a variable and pass it to the database using a POST request. You can use a "WHERE column_name = input_value" and when you get the response, check the length.

If the length is > 0, it means there is a value with the user input data.

This is what I can think of now.

Please follow this for a POST request.

How do I send a POST request with PHP?

arunmmanoharan
  • 2,535
  • 2
  • 29
  • 60
0

Use PDO database library. This might help you : https://www.w3schools.com/php/showphpfile.asp?filename=demo_db_select_pdo

Since you said you are new to PHP, know the difference between "isset" and "empty" and "false" check (both "==" and "===")? The below resources might help you :

In where shall I use isset() and !empty()

http://www.sitepoint.com/forums/showthread.php?534119-isset()-vs-!empty()-vs-!-null-vs-!-quot-quot-vs-var

sudip
  • 2,781
  • 1
  • 29
  • 41