-3

I am new to html & php and I appreciate your help. I am trying to accept user input into a webpage and then after the user clicks the submit button, write a new record out to MySQL. I am using Wordpress so the tags are not exactly textbook. So my first problem is that the submit button does not appear to execute the php code. I also would appreciate it if someone could check how I am passing my html field names to the php variables to make sure that I am on the right track. Thanks for your help!

     <form
      action="employee_list.php" method="post"
           <input type="submit"
         name="passport" id="passport" action="uraction" method="post" enctype="multipart/form-data"
    <label for="upload" >Select Employee Passport</label><input type="file" id="upload" name="upload" accept="image/*">
    <p/>
    <div class="form-group">
       <div class="form-row">
          <div class="col-md-6">
             <label for="name">Employee Full  Name</label>
             <input type="text" class="form-control" id="exampleInputName" aria-describedby="nameHelp" placeholder="Enter Full Name">
          </div>
          <div class="col-md-6">
             <label for="gender">Gender</label>
             <select type="text" class="form-control" id="exampleInputLastName" aria-describedby="nameHelp">
             </select>
          </div>
          <div class="col-md-6">
             <label for="maritalstatus">Marital Status</label>
             <select type="text" class="form-control" id="exampleInputLastName" aria-describedby="nameHelp">
             </select>
          </div>
          <div class="col-md-6">
             <label for="department">Department</label>
             <input type="text" class="form-control" id="Position" aria-describedby="nameHelp" placeholder="Enter The Department">
          </div>
          <div class="col-md-6">
             <label for="salary">Salary</label>
             <input type="number" class="form-control" id="salary" aria-describedby="nameHelp" placeholder="">
          </div>
          <div class="col-md-6">
             <label for="certificate"> Highest Certificate Acquired</label>
             <input type="text" class="form-control" id="salary" aria-describedby="nameHelp" placeholder="Enter  Highest Certificate Acquired">
          </div>
       </div>
    </div>
    <div class="form-group">
       <label for="Email">Email Address</label>
       <input type="emai" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email">
    </div>
    <div class="form-group">
       <label for="address">House Address</label>
       <input type="text" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter House Address">
    </div>
    <div class="form-group">
    <div class="form-row">
       <div class="col-md-6">
          <label for="phonenumber">Phone Number</label>
          <input type="number" class="form-control" id="phonenumber">
       </div>
       </form>
    </div>
    <!-- /.content-wrapper -->



    PHP script:
    <?php 
       if(isset($_POST['submit'])) { 
           $SQL = "INSERT INTO tbl_employee (name, gender, 
           marital_status,department,salary,certificate, email,address,phone_number) 
           VALUES ('$_POST[name]', '$_POST[gender]', 
           '$_POST[marital_status],'$_POST[department]','$_POST[salary]‌​
           ','$_POST[certificat‌​
           e]','$_POST[email]',‌​'$_POST[address]','$‌​_POST[phone_numer]')‌​"; $result = 
           mysql_query($SQL); 
       } 
       ?>   
pramod24
  • 1,096
  • 4
  • 17
  • 38
  • your form looks unfinished and isn't well formed and please don't post code in comments, edit your post instead. – Funk Forty Niner Sep 11 '17 at 13:14
  • Put the code in the question, not in the comments, please @KanuUgochukwu – Qirel Sep 11 '17 at 13:15
  • 2
    Every time you use [the `mysql_`](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) database extension in new code **[this happens](https://media.giphy.com/media/kg9t6wEQKV7u8/giphy.gif)** it is deprecated and has been for years and is gone for ever in PHP7. If you are just learning PHP, spend your energies learning the `PDO` or `mysqli` database extensions and prepared statements. [Start here](http://php.net/manual/en/book.pdo.php) – RiggsFolly Sep 11 '17 at 13:19
  • 1
    Your script is at risk of [SQL Injection Attack](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) Even [if you are escaping inputs, its not safe!](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string) Use [prepared parameterized statements](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) – RiggsFolly Sep 11 '17 at 13:19
  • **Missing single quote** `'$_POST[marital_status],` – RiggsFolly Sep 11 '17 at 13:20
  • but when i run it , it does not save data in to the data base, please what should i do – Kanu Ugochukwu Sep 11 '17 at 13:25
  • 1
    inputs don't have a method nor an action; recheck your form syntax – Funk Forty Niner Sep 11 '17 at 13:28
  • @Fred-ii- please where exactly do you think the problem is please am stuck here – Kanu Ugochukwu Sep 11 '17 at 13:31
  • Your `
    ` tag is completely invalid. You need to write valid HTML, and fix that code.
    – Kirk Beard Sep 11 '17 at 13:40

1 Answers1

1
 <html>
<head>
    <title>Check</title>
    <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

    <!-- jQuery library -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

    <!-- Latest compiled JavaScript -->
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 

</head>
<body>
    <?php include('dbconnect.php');

    if($_POST['submit']){
        $fullname = $_POST['exampleInputName'];
        $gender = $_POST['gender'];
        $status = $_POST['status'];
        $position = $_POST['position'];
        $salary = $_POST['salary'];
        $certificate = $_POST['certificate'];
        $exampleInputEmail1 = $_POST['exampleInputEmail1'];
        $phonenumber = $_POST['phonenumber'];            
    }        

    $data = "INSERT INTO test (`id`, `fullname`, `gender`, `matrial_status`, `department`, `salary`, `certificate`, `email`, `address`)VALUES ('', '$fullname', '$gender', '$status', '$position', '$salary', '$certificate', '$exampleInputEmail1', '$phonenumber')";        

    mysqli_query($con,$data);

    ?>
    <form action="checkbox.php" method="POST" >
        <div class="form-group">
            <div class="form-row">
                <div class="col-md-6">
                    <label for="name">Employee Full  Name</label>
                    <input type="text" class="form-control" id="exampleInputName" name="exampleInputName" aria-describedby="nameHelp" placeholder="Enter Full Name">
                </div>
                <div class="col-md-6">
                    <label for="gender">Gender</label>
                    <select type="text" name="gender" class="form-control" id="gender" aria-describedby="nameHelp">
                        <option value="Male">Male</option>
                        <option value="Female">Female</option>
                    </select>
                </div>

                <div class="col-md-6">
                    <label for="maritalstatus">Marital Status</label>
                    <select type="text" name="status" class="form-control" id="status" aria-describedby="nameHelp">
                        <option value="Married">Married</option>
                        <option value="Unmarried">Unmarried</option>
                    </select>
                </div>
                <div class="col-md-6">
                    <label for="department">Department</label>
                    <input type="text" class="form-control" name="position" id="position" aria-describedby="nameHelp" placeholder="Enter The Department">
                </div>
                <div class="col-md-6">
                    <label for="salary">Salary</label>
                    <input type="number" class="form-control" name="salary" id="salary" aria-describedby="nameHelp" placeholder="">
                </div>
                <div class="col-md-6">
                    <label for="certificate"> Highest Certificate Acquired</label>
                    <input type="text" class="form-control" id="certificate" name="certificate" aria-describedby="nameHelp" placeholder="Enter  Highest Certificate Acquired">
                </div>
            </div>
        </div>
        <div class="form-group">
            <label for="Email">Email Address</label>
            <input type="emai" class="form-control" id="exampleInputEmail1" name="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email">
        </div>
        <div class="form-group">
            <label for="address">House Address</label>
            <input type="text" class="form-control" id="exampleInputEmail1" name="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter House Address">
        </div>
        <div class="form-group">
            <div class="form-row">
                <div class="col-md-6">
                    <label for="phonenumber">Phone Number</label>
                    <input type="text" class="form-control" name="phonenumber" id="phonenumber">
                </div>
            </div>
        </div>

        <input type="submit" name="submit" id="passport">
    </form>
</body>

Mayank
  • 56
  • 3
  • you have to change your code with the help of this code , it will work @KanuUgochukwu .! This is tested code. – Mayank Sep 12 '17 at 05:59