Stop Submit With empty and error Input Values Using PHP
        Posted  
        
            by 
                user3615781
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by user3615781
        
        
        
        Published on 2014-05-29T21:23:06Z
        Indexed on 
            2014/05/29
            21:24 UTC
        
        
        Read the original article
        Hit count: 203
        
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));
}       
?>
© Stack Overflow or respective owner