how to check data already exist in database in php & email already exist validation in php

0
()

how to check data already exist in database in php best 2 Ways To Check if Email already exists Using PHP Example and demo with To check if email already exists in database using PHP.

how to check data already exist in database in php

how to check email already exist in database in php To check if a particular value exists in the database, all you required to do is run a SELECT query.

how to check if an email address already exists in the database in php?

Set Email Column as UNIQUE on the Database

<?php
$link = mysqli_connect("localhost","root","","members");
if (isset($_POST['checkEmail'])) {
  $email = $_POST['email'];
  $insData = mysqli_query($link, "INSERT INTO `members`(`email`) VALUES('$email')") or die(mysqli_error($con));
}
?>
<form method="POST">
  Email:<br>
  <input type="email" name="email" required><br><br>
  <button name="checkEmail">Validate Email</button>
</form>

Don’t Miss : How To Check Email Already Exist In Database In Php

Free Live Chat for Any Issue

Validate Email using MySQL SELECT query with WHERE clause

<?php
$link = mysqli_connect("localhost","root","","members");
if (isset($_POST['register'])) {
  $email = $_POST['email'];
  $sql = "SELECT * FROM members WHERE email='$email'";
  $data = mysqli_query($db, $sql);

  if(mysqli_num_rows($data) > 0){
    $email_error = "Sorry... member email already taken";  
  }else{
    $query = mysqli_query($link, "INSERT INTO `members`(`email`) VALUES('$email')");
    echo 'Saved!';
  }
}

How To Check If A Record Exists In A MySQL Database?

$query = "SELECT * FROM members WHERE mcode = '$mcode'";
$result = mysql_query($query);
if ($result) {
  if (mysql_num_rows($result) > 0) {
    echo 'found!';
  } else {
    echo 'not found';
  }
} else {
  echo 'Error: '.mysql_error();
}

Best way to test if a row exists in a MySQL table

Read Also:  WooCommerce Get Product Reviews

mysql> SELECT EXISTS(SELECT * from members WHERE memberID=5623);

//AND

mysql> SELECT EXISTS(SELECT * from members WHERE memberID=5658);

Download

I hope you get an idea about how to check data already exist in database in php.
I would like to have feedback on my infinityknow.com.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Read Also:  Laravel ajax post CSRF Protection

How useful was this post?

Click on a star to rate it!