Stop Submit With empty and error Input Values Using PHP
- by user3615781
I am using the following code for sending data to database, but it sends the data even the values of the fields are incorrect or empty. So can anyone help me solve this by using php?
Here is my code:
<?php
//Connecting to sql db
$connect = mysqli_connect("localhost","root","","form");
/* check connection */
if (!$connect) {
die('Connect Error: ' . mysqli_connect_error());
}
//Sending data to sql db
$result = mysqli_query($connect,"INSERT INTO students(name,email,website,comment,gender)
VALUES('$name','$email','$website','$comment','$gender')");
if (!$result) {
die('Query Error:'. mysqli_error($connect));
}
?>