I cant inserting data into database.It does not show any error to.Please help me

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
 
<div class="container"> 
<div class="row">
<div class="col-sm-10" height="auto">
  <div class="panel panel-info">
  <div class="panel-heading"><h2>Blood Bank Registration Form</h2></div>
  <div class="panel-body"> 
  
  <form class="form-horizontal" method="POST" action="bloodbankindex.php">
  
  <div class="form-group">  
    <label class="control-label col-sm-2" for="Name">Name:</label>
    <div class="col-sm-8">
      <input type="text" class="form-control" name="name" placeholder="Enter Your Name" required>
    </div>
  </div> 
  <div class="form-group">
    <label class="control-label col-sm-2" for="fathername">Father Name:</label>
    <div class="col-sm-8"> 
      <input type="text" class="form-control" name="fathername" placeholder="Enter Your Father Name" required>
    </div>
  </div>  
  <div class="form-group">
    <label class="control-label col-sm-2" for="mothername">Mother Name:</label>
    <div class="col-sm-8">
      <input type="text" class="form-control" name="mothername" placeholder="Enter Your Mother Name" required>
    </div>
  </div>  
  <div class="form-group">
    <label class="control-label col-sm-2" for="address">Address:</label>
    <div class="col-sm-8"> 
      <input type="text" class="form-control" name="address" placeholder="Enter Your Address" required>
    </div>
  </div>  
  <div class="form-group">
    <label class="control-label col-sm-2" for="email">Email:</label>
    <div class="col-sm-8">
      <input type="email" class="form-control" name="email" placeholder="Enter Your Email Address">
    </div>
  </div>  
  <div class="form-group">
    <label class="control-label col-sm-2" for="district">District Name:</label>
    <div class="col-sm-8"> 
      <input type="text" class="form-control" name="district" placeholder="Enter Your District Name" required>
    </div>
  </div> 
  <div class="form-group">
    <label class="control-label col-sm-2" for="nationality">Nationality:</label>
    <div class="col-sm-8"> 
      <input type="text" class="form-control" name="nationality" placeholder="Enter Your Country Name" required>
    </div>
  </div> 
  <div class="form-group">
    <label class="control-label col-sm-2" for="birthdaycirtificate">Birthday Certificate No.:</label>
    <div class="col-sm-8">
      <input type="text" class="form-control" name="birthdaycirtificate" placeholder="Enter Your Birthday Cirtificate No.">
    </div>
  </div> 
  <div class="form-group">
    <label class="control-label col-sm-2" for="nationalid">National ID:</label>
    <div class="col-sm-8"> 
      <input type="text" class="form-control" name="nationalid" placeholder="Enter Your National ID">
    </div>
  </div>   
  <div class="form-group">
    <label class="control-label col-sm-2" for="moblilenumber">Mobile Number:</label>
    <div class="col-sm-8">
      <input type="text" class="form-control" name="moblilenumber" placeholder="Enter Your Mobile Number" required>
    </div>
  </div> 
 <div class="form-group">
  <label class="control-label col-sm-2" for="religion">Religion:</label>
  <div class="col-sm-8"> 
  <select name="religion" required>
    <option value="select">Select</option>
    <option value="muslim">Muslim</option>
    <option value="hindu">Hindu</option>
    <option value="chiristian">Chirstian</option>
    <option value="buddha">Buddha</option>
	<option value="others">Others</option>
  </select>
  </div>
</div> 

<div class="form-group">
 <label class="control-label col-sm-2" for="birthday">Birthday:</label>
  <div class="col-sm-8">
  <input type="date" class="form-control" name="birthday" placeholder="Enter Your Birthday Date" >
</div></div>
  
  <div class="form-group">
  <label class="control-label col-sm-2" for="gender">Gender</label>
  <div class="col-sm-8">
  <input type="radio" name="gender" value="male" checked>Male
  <input type="radio" name="gender" value="female" >Female
  <input type="radio" name="gender" value="others" disabled>Others
  </div>
  </div> 
  <div class="form-group">
  <label class="control-label col-sm-2" for="bloodgroup">Blood Group:</label>
  <div class="col-sm-8"> 
  <select name="bloodgruop" required>
    <option value="select">Select</option>
    <option value="a+">A+</option>
    <option value="a-">A-</option>
    <option value="ab+">AB+</option>
    <option value="ab-">AB-</option>
	<option value="b+">B+</option>
    <option value="b-">B-</option>
    <option value="o+">O+</option>
    <option value="o-">O-</option>
  </select>
  </div>
</div>   
   <div class="form-group">
  <label class="control-label col-sm-2" for="hbs">Has any HBS+:</label>
  <div class="col-sm-8">
  <input type="radio" name="hbs" value="yes" checked>Yes
  <input type="radio" name="hbs" value="no"> No
  </div>
  </div>  
  <div class="form-group">
  <label class="control-label col-sm-2" for="hiv">Has any HIV+:</label>
  <div class="col-sm-8">
  <input type="radio" name="hiv" value="yes" checked>Yes
  <input type="radio" name="hiv" value="no"> No
  </div>
  </div> 
  <div class="form-group">
  <label class="control-label col-sm-2" for="maleria">Has any Maleria:</label>
  <div class="col-sm-8">
  <input type="radio" name="maleria" value="yes" checked>Yes
  <input type="radio" name="maleria" value="no"> No
  </div>
  </div> 
  <div class="form-group">
  <label class="control-label col-sm-2" for="anemia">Has any Anemia:</label>
  <div class="col-sm-8">
  <input type="radio" name="anemia" value="yes" checked>Yes
  <input type="radio" name="anemia" value="no"> No
  </div>
  </div> 
   <div class="form-group">
  <label class="control-label col-sm-2" for="area">Area You Want To Donate:</label>
  <div class="col-sm-8"> 
  <select name="area" required>
    <option value="select">Select</option>
    <option value="anywhere">Any Where</option>
    <option value="insidegognogor">Inside Gognogor UP</option>
    <option value="insidenarayangonj">Inside Narayangonj</option>
	<option value="alltheplacesinside dhaka">All The Places Inside Dhaka</option>
  </select>
  </div>
</div> 
  <div class="form-group"> 
    <div class="col-sm-offset-2 col-sm-10">
      <button type="submit" class="btn btn-success">Submit</button>
	  <button type="reset" class="btn btn-primary">Reset</button>
    </div>
  </div>
  

</div>
</div>
</div>
</div>
</body>
</html>


 <?php 
$id="";
$name="";
$fathername="";
$mothername="";
$address="";
$email="";
$district="";
$nationality="";
$birthdaycirtificate="";
$nationalid="";
$moblilenumber="";
$religion="";
$birthday="";
$gender="";
$bloodgruop="";
$hbs="";
$hiv="";
$maleria="";
$anemia="";
$area="";

if(isset($_POST["submit"])){	
	$name=$_POST["name"];
	$fathername=$_POST["fathername"];
	$mothername=$_POST["mothername"];	
   	$address=$_POST["address"];
	$email=$_POST["email"];
	$district=$_POST["district"];
    $nationality=$_POST["nationality"];
	$birthdaycirtificate=$_POST["birthdaycirtificate"];
	$nationalid=$_POST["nationalid"];
	$moblilenumber=$_POST["moblilenumber"];
	$religion=$_POST["religion"];
	$birthday=$_POST["birthday"];
    $gender=$_POST["gender"];	
    $bloodgroup=$_POST["bloodgroup"];
	$hbs=$_POST["hbs"];
	$hiv=$_POST["hiv"];
	$maleria=$_POST["maleria"];
	$anemia=$_POST["anemia"];
	$area=$_POST["area"];



$servername = "localhost";
$username = "root";
$password = "";
$dbname = "blood_bank";

// Create connection
$conn = new mysqli($servername,$username,$password,$dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed:".$conn->connect_error);
} 
  $sql = "INSERT INTO blood_bank_db(name,fathername,mothername,address,email,district,nationality,birthdaycirtificate,nationalid,religion,birthday,gender,bloodgroup,hbs,hiv,maleria,anemia,area)
  VALUES ('$name', '$fathername','$mothername','$address','$email','$district','$nationality','$birthdaycirtificate','$nationalid','$religion','$birthday','$gender','$bloodgroup','$hbs','$hiv','$maleria','$anemia','$area')";
  
  
if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();

}

?>

You’re a sitting duck for SQL injection attacks as your using user submitted data without even attempting to validate any of the data submitted by the user. You should use prepared statements when sending any data to a database server

4 Likes

You don’t have a name parameter on your submit button

<button type="submit" class="btn btn-success">Submit</button>

So this line fails

if(isset($_POST["submit"])){	

so none of your other code is executed.

2 Likes

thankx its working

Look at this piece of mysqli documentation and it’s related functions to prevent your site from being invaded:
https://php.net/manual/pt_BR/mysqli.prepare.php

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.