Guest User

Untitled

a guest
Jun 6th, 2016
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.93 KB | None | 0 0
  1. <html>
  2.    
  3.    <head>
  4.       <title>Add New Record in MySQL Database</title>
  5.    </head>
  6.    
  7.    <body>
  8.       <?php
  9.          if(isset($_POST['add'])) {
  10.             $dbhost = 'localhost:3036';
  11.             $dbuser = 'root';
  12.             $dbpass = 'rootpassword';
  13.             $conn = mysql_connect($dbhost, $dbuser, $dbpass);
  14.            
  15.             if(! $conn ) {
  16.                die('Could not connect: ' . mysql_error());
  17.             }
  18.            
  19.             if(! get_magic_quotes_gpc() ) {
  20.                $emp_name = addslashes ($_POST['emp_name']);
  21.                $emp_address = addslashes ($_POST['emp_address']);
  22.             }else {
  23.                $emp_name = $_POST['emp_name'];
  24.                $emp_address = $_POST['emp_address'];
  25.             }
  26.            
  27.             $emp_salary = $_POST['emp_salary'];
  28.            
  29.             $sql = "INSERT INTO employee ". "(emp_name,emp_address, emp_salary,
  30.               join_date) ". "VALUES('$emp_name','$emp_address',$emp_salary, NOW())";
  31.                
  32.             mysql_select_db('test_db');
  33.             $retval = mysql_query( $sql, $conn );
  34.            
  35.             if(! $retval ) {
  36.                die('Could not enter data: ' . mysql_error());
  37.             }
  38.            
  39.             echo "Entered data successfully\n";
  40.            
  41.             mysql_close($conn);
  42.          }else {
  43.             ?>
  44.            
  45.                <form method = "post" action = "<?php $_PHP_SELF ?>">
  46.                   <table width = "400" border = "0" cellspacing = "1"
  47.                      cellpadding = "2">
  48.                  
  49.                      <tr>
  50.                         <td width = "100">Employee Name</td>
  51.                         <td><input name = "emp_name" type = "text"
  52.                            id = "emp_name"></td>
  53.                      </tr>
  54.                  
  55.                      <tr>
  56.                         <td width = "100">Employee Address</td>
  57.                         <td><input name = "emp_address" type = "text"
  58.                            id = "emp_address"></td>
  59.                      </tr>
  60.                  
  61.                      <tr>
  62.                         <td width = "100">Employee Salary</td>
  63.                         <td><input name = "emp_salary" type = "text"
  64.                            id = "emp_salary"></td>
  65.                      </tr>
  66.                  
  67.                      <tr>
  68.                         <td width = "100"> </td>
  69.                         <td> </td>
  70.                      </tr>
  71.                  
  72.                      <tr>
  73.                         <td width = "100"> </td>
  74.                         <td>
  75.                            <input name = "add" type = "submit" id = "add"
  76.                               value = "Add Employee">
  77.                         </td>
  78.                      </tr>
  79.                  
  80.                   </table>
  81.                </form>
  82.            
  83.             <?php
  84.          }
  85.       ?>
  86.    
  87.    </body>
  88. </html>
Add Comment
Please, Sign In to add comment