This question already has an answer here:
- check if row exists with mysql 3 answers
I have a question on how to check if a school exists within the database i have made? I have provided the MYSQLI code below. If you see any syntax errors can you please help me fix them. Thank you for your help i really appreciate it.
$connection = mysqli_connect("localhost", "root", "root", "babble");
$check ="SELECT COUNT(1) FROM schools WHERE schoolname = '$_POST[schoolname]'";
$result = mysqli_query($connection,$check);
$data = mysqli_fetch_array($result, MYSQLI_NUM);
if ($data[0] > 1) {
echo "<center><div class='alert alert-danger'><p>Sorry, but that school already exists in the database</p></div></center>";
}else{
$insert = "INSERT INTO schools";
}
</div>