Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
PHP
<?php 
  $mysql_hostname = "localhost";
  $mysql_user = "root";
  $mysql_password = "";
  $mysql_database = "loan";
  $connect = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) 
  or die("Something went wrong...");
  mysql_select_db($mysql_database, $connect) or die("Something went wrong...");


  if(isset($_POST['submit']))   
  {   
    $datess = $_POST['datess'];
    $control = $_POST['control'];  
    $payee = $_POST['payee'];                            
      if(!empty($datess) && !empty($control) && !empty($payee))
          {
                  mysql_query("INSERT INTO `sales`(`datess`, `control`, `payee`)
                   VALUES ('$datess', '$control', '$payee')");
          }
        else
          {
            //   echo "<script type='text/javascript'>alert('Please Dont Leave Blank Field.')</script>";
    
          }    
    }

    ?>

<html>
<body>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
  
  
<center>            

                    <form action="" method="post">
    <label>
      Date
      <input type="text" name="datess">
    </label>
    <label>
      Control Number
      <input type="number" name="control">
    </label>

   <label>
      Payee
      <input type="text" name="payee">
    </label>
   
</form>
  <!-- Trigger the modal with a button -->
 <div class="usman"> <button type="submit" name="btn_submit" class="btn btn-info" data-toggle="modal" data-target="#myModal" tabindex="14"><strong>Confirm</strong></button>
 
</div>

  <!-- Modal -->
  <div class="modal fade" id="myModal" role="dialog">
    <div class="modal-dialog">
    
      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <h5 class="modal-title">Confirmation</h5> 
        </div>
        <div class="modal-body"> 
       <h4><font color="red"> Are you sure ? </font></h4>
       
        </div>
        <div class="modal-footer">
          <button type="submit" name="submit" class="btn btn-success"  data-dismiss="modal">Save</button>
        </div>
      </div>
      
    </div>
  </div>
</div>
</body>
</html>
Posted
Comments
Nathan Minier 15-Dec-15 13:09pm    
You code is begging for SQL injection. You need to sanitize input before sending it to the database.

Also, just put a form in the modal with the submit action being this php file.
Abim usman 15-Dec-15 13:32pm    
This my complete code! yes im beginner. i need your help!!



alert('Please Dont Leave Blank Field.')</script>";

}
}

?>

<html>
<body>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>




<form action="" method="post">
<label>
Date
<input type="text" name="datess">
</label>
<label>
Control Number
<input type="number" name="control">
</label>

<label>
Payee
<input type="text" name="payee">
</label>

</form>
<!-- Trigger the modal with a button -->
<div class="usman"> <button type="submit" name="btn_submit" class="btn btn-info" data-toggle="modal" data-target="#myModal" tabindex="14">Confirm</button>

</div>

<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">

<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">

</div>
<div class="modal-body">

Are you sure ?



</div>
<div class="modal-footer">
<button type="submit" name="submit" class="btn btn-success" data-dismiss="modal">Save</button>
</div>
</div>

</div>
</div>
</div>
</body>
</html>
Nathan Minier 15-Dec-15 15:15pm    
I was saying that your code has a very big security hole in it, called SQL Injection.

Your code is a bit all over the place, it will not work the way you mean for it to.

First give your form an id and set the action to the url of your PHP, such as:
<form id="myForm" action="you.php.page" method="post">

Change your button to:
<button id="btn_submit" class="btn btn-info" data-toggle="modal" data-target="#myModal" tabindex="14">Confirm</button>

And finally, change the button on the modal:
<button class="btn btn-success" data-dismiss="modal" on-click="$('#myForm').submit()">Save</button>

And please, please fix the SQL injection. Google it for help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900