Free download web templates, books and more. Free php projects ,games and apps. GTA mods and more

Breaking

php mysqli contact form example || php mysql contact form source code

php mysqli contact form example:

this contact form example by putting this code into add_employee.php, this will take input using HTML Form and then it will create records into database.
<html>
   
   <head>
      <title>Add New Record in MySQL Database</title>
   </head>
   



   <body>
      <?php
         if(isset($_POST['add'])) {
            $dbhost = 'localhost';
            $dbuser = 'root';
            $dbpass = '';
            $conn = mysql_connect($dbhost, $dbuser, $dbpass);
            
            if(! $conn ) {
               die('Could not connect: ' . mysql_error());
            }
            
            if(! get_magic_quotes_gpc() ) {
               $name = addslashes ($_POST['name']);
               $address = addslashes ($_POST['address']);
            }else {
               $name = $_POST['name'];
               $address = $_POST['address'];
            }
            
            $phone_number = $_POST['phone_number'];
            
            $sql = "INSERT INTO contact ". "(name,address, phone_number, 
               join_date) ". "VALUES('$name','$address',$phone_number, NOW())";
               
            mysql_select_db('test_db');
            $retval = mysql_query( $sql, $conn );
            
            if(! $retval ) {
               die('Could not enter data: ' . mysql_error());
            }
            
            echo "Entered data successfully\n";
            
            mysql_close($conn);
         }else {
            ?>
            
               <form method = "post" action = "<?php $_PHP_SELF ?>">
                  <table width = "400" border = "0" cellspacing = "1" 
                     cellpadding = "2">
                  
                     <tr>
                        <td width = "100"> User Name</td>
                        <td><input name = "name" type = "text" 
                           id = "emp_name"></td>
                     </tr>
                  
                     <tr>
                        <td width = "100">Address</td>
                        <td><input name = "address" type = "text" 
                           id = "address"></td>
                     </tr>
                  
                     <tr>
                        <td width = "100">Mobile Number</td>
                        <td><input name = "phone_number" type = "text" 
                           id = "phone_number"></td>
                     </tr>
                  
                     <tr>
                        <td width = "100"> </td>
                        <td> </td>
                     </tr>
                  
                     <tr>
                        <td width = "100"> </td>
                        <td>
                           <input name = "add" type = "submit" id = "add" 
                              value = "Submit">
                        </td>
                     </tr>
                  
                  </table>
               </form>
            
            <?php
         }
      ?>
   
   </body>
</html>