0

i am trying to get connected to database .html page doesnt get connected to addtodatabase.php which has many feilds like radio button,checkbox,textarea, input field .Once given submit it doesn't display the data .

  <form action="addtodatabase.php" method="post">
  <div class="container">
  <form class="form-inline">
    <fieldset>
    <legend>Security Department User Registration</legend>
    <div class="form-group">

    <label for="Firstname">First Name</label>

    <input type="text" class="form-control" id="Firstname"  name="Firstname" placeholder="Text input"><br/>                                                                                   
    </div>

    <div class="form-group">
    <label for="Secondname">Second Name</label>
    <input type="text" class="form-control" id="Secondname" name="Secondname" placeholder="Text input"><br/>
    </div>
</form>

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

addtodatabase.php page as phpmyadmin username as root , pasword NULL

     <?php
      $connection = mysql_connect ('root','','');
      mysql_select_db('form_db');

      $Firstname =      $_POST ['Firstname'];
      $Secondname =     $_POST ['Secondname'];




     echo $_POST['Firstname'];
     echo '<br />';
     echo $_POST['Secondname'];

    $query = 
    "INSERT INTO form_details
     (Firstname,Secondname)

     values

     ('$Firstname','$Secondname')";

     $result = mysql_query($query);
     Echo "Database Saved"; 
    mysql_close($connection);
  ?>

i have change the code from mysql to mysqli

    <?php


   $connect=mysqli_connect('localhost','root','','form_db');

   if(mysqli_connect_errno($connect))
   {
    echo 'Failed to connect';
   }


   $Firstname = $_POST ['Firstname'];
   $Secondname =$_POST ['Secondname'];

   echo $_POST['Firstname'];
   echo '<br />';
   echo $_POST['Secondname'];

   $query = 
  "INSERT INTO form_details
   (Firstname,Secondname)

   values

   ('$Firstname','$Secondname')";

   $result = mysqli_query($query);
   if(mysqli_affected_rows($connect) > 0){
   echo "<p>Employee Added</p>";
   echo "<a href="index.html">Go Back</a>";
   } else {
   echo "Employee NOT Added<br />";
   echo mysqli_error ($connect);
   }

  ?>

Even after changing to mysqli it not working .addtodatabase.php I am getting this error Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:\wamp64\www\Form\addtodatabase.php on line 2

My entire form looks this way

  <!DOCTYPE html>
  <html>
  <head> 
  <link rel="stylesheet" href="css/bootstrap.min.css">
  <link rel="stylesheet" href="customstyle.css">
  </head>
  <body>
  <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
  <script src="js/bootstrap.min.js"></script>

  <form action="addtodatabase.php" method="post">
  <div class="container">

 <h1> Group of Companies</h1>
 <h3> ICT & Security Department User Registration form </h3>
 <h4> To be filled  by HR department for New Employee </h4>


  <form class="form-inline">
    <fieldset>
    <legend>Security Department User Registration</legend>
    <div class="form-group">
        <label for="Firstname">First Name</label>
        <input type="text" class="form-control" id="Firstname" name="Firstname" placeholder="Text input"><br/>
    </div>

    <div class="form-group">
    <label for="Secondname">Second Name</label>
    <input type="text" class="form-control" id="Secondname" name="Secondname" placeholder="Text input"><br/>
    </div>
</form>

<form >
    <div class="form-group">
    <label for="location">Dpt./Location</label>
    <input type="text" class="form-control"  name="location" id="location" placeholder="Text input">
    </div>
</form>

<form class="form-inline">
    <div class="form-group">
    <label for="Designation">Designation</label>
    <input type="text" class="form-control" id="Designation" placeholder="Text input"><br/>
    </div>

    <div class="form-group">
    <label for="Fileno">File No</label>
    <input type="text" class="form-control" id="Fileno" placeholder="Password"><br/>
    </div>
</form> 


<form class="form-inline">
    <div class="form-group">
    <label for="Dateofapplication">Date of Application</label>
    <input type="text" class="form-control" id="Dateofapplication" placeholder="Text input"><br/>
    </div>

    <div class="form-group">
    <label for="Dateofjoining">Date of Joining</label>
    <input type="text" class="form-control" id="Dateofjoining" placeholder="Password"><br/>
    </div>
</form> 


<form>
    <fieldset>
    <legend>For Head office staffs only </legend>
    <label>Card Type:</label>

    <div id="idcard">

    <label class="checkbox-inline">
    <input type="checkbox" value="">Trainee ID Card
    </label>

    <label class="radio-inline">
    <input type="radio" name="green">Green
    </label>

    <label class="radio-inline">
    <input type="radio" name="red">Red
    </label>

    <label class="checkbox-inline">
    <input type="checkbox" value="">Permanent ID Card
    </label>

    </div>

    <div class="aligncheckbox">

    <label>Door Access:</label>
    <label class="checkbox-inline">
    <input type="checkbox" value="">Main
    </label>

    <label class="checkbox-inline">
    <input type="checkbox" value="">Finance Division
    </label>
    </div>
    <div class="aligncheckbox">
    <label class="checkbox-inline">
    <input type="checkbox" value="">Meeting Room
    </label>

    <label class="checkbox-inline">
    <input type="checkbox" value="">Goods Receiving
    </label>
    </div>

    <div class="aligncheckbox">
    <label class="checkbox-inline">
    <input type="checkbox" value="">Graphics & Media
    </label>

    <label class="checkbox-inline">
    <input type="checkbox" value="">IT Dept
    </label>
    </div>

    <div class="aligncheckbox">
    <label class="checkbox-inline">
    <input type="checkbox" value="">Server Room
    </label>

    <label class="checkbox-inline">
    <input type="checkbox" value="">Dist.&Quality Control
    </label>
    </div>

    <div class="aligncheckbox">
    <label class="checkbox-inline">
    <input type="checkbox" value="">Warehouse Supervisor
    </label>

    <label class="checkbox-inline">
    <input type="checkbox" value="">Pur.Office Meeting Room
    </label>
    </div>
    <div class="aligncheckbox">

    <label class="checkbox-inline">
    <input type="checkbox" value="">Purchase Office
    </label>

    <label class="checkbox-inline">
    <input type="checkbox" value="">Exit
    </label>
    </div>





<!--    <div class="upload">

    <label for="Passportcopy">Passport Copy</label>
    <input type="file" id="Passportcopy">


    <label for="Photo">Photo</label>
    <input type="file" id="Photo">

    </div>  

    <div>

    <label class="checkbox-inline">
    <input type="checkbox" value="">Finger Registration
    </label>

    </div> -->

   <div class="container">

   <div id="upload row">
   <form class="form-inline">
     <div class="form-group col-xs-*">
     <label for="Passportcopy">Passport Copy</label>
      <input type="file" class="form-control" id="Passportcopy">
     </div>
     <div class="form-group col-xs-*">
      <label for="Photo">Photo</label>
      <input type="file" class="form-control" id="Photo">
     </div>

     </form>

    </div>
    </div>












  </form>



    <!-- second form IT department -->
    <div class="secform">

    <form>
    <fieldset>
    <legend>IT Department User Registration </legend>


    <div class="container">

    <form class="form-inline">

    <div class="checkbox-inline" id="erp">
    <label><input type="checkbox" value="">Enroll as sales Person ERP</label>
    </div>

    <div class="form-group" id="textbox">
    <label for="erpmodules">ERP Modules</label>
    <textarea class="form-control" rows="5" id="erpmodules"></textarea>
    </div>

    </fieldset>

    </form>



    <form>
    <fieldset>
    <legend>For Head office staffs only </legend>

    <div class="fkhaccess">
    <div class="form-group" id="textbox">
    <label for="fkhaccess">FKH Folder Access</label>
    <textarea class="form-control" rows="5" id="fkhaccess"></textarea>
    </div>

    <div class="container-fluid">

    <ul id="access">
    <li>    <label>Internet Access</label></li>
    <li>
    <label class="radio-inline">
        <input type="radio" name="yes">Yes
    </label></li>
    <li>
    <label class="radio-inline">
        <input type="radio" name="no">No
    </label></li>
    </ul>

    <ul id="purpose">
    <li><p>If yes, Purpose </p></li>
    <li>
    <div class="form-group" id="textbox">
    <label for="purpose">Job Purpose</label>
    <textarea class="form-control" rows="5" id="purpose"></textarea>
    </div></li>
    </ul>


    <ul id="compmail">
    <li>
    <div class="form-group" id="textbox" >
    <label for="companyemail">Company Email</label>
    <textarea class="form-control" rows="5" id="companyemail"></textarea>
    </div></li>
    </ul>





    <form class="form-inline">

    <label> Computer facilities: </label>
    <label> CD ROM </label>
    <label class="checkbox-inline">
    <input type="checkbox" value="">Read
    </label>

    <label class="checkbox-inline">
    <input type="checkbox" value="">Write
    </label>

    <label> USB PORTS </label> 
    <label class="checkbox-inline">
    <input type="checkbox" value="">Read
    </label>

    <label class="checkbox-inline">
    <input type="checkbox" value="">Write
    </label>

    </form>

    <form class="form-inline">
    <label class="checkbox-inline"  id="label1">
    <input type="checkbox"  value="">Parallel Port 
    </label>
    </form>


    <form class="form-inline">

    <label> Printers </label>

    <label class="checkbox-inline">
    <input type="checkbox" value="">MP2352(Front Office)
    </label>

    <label class="checkbox-inline">
    <input type="checkbox" value="">MP2501(Purchase)
    </label>
    </form>

    <form class="form-inline">
    <label class="checkbox-inline">
    <input type="checkbox" value="">MP1600(MD Office)
    </label>

    <label class="checkbox-inline">
    <input type="checkbox" value="">DSM616(Finance)
    </label>

    </form>





    <form class="form-inline">
    <ul><li>
    <label> Computer Utilities :</label>
    <label class="checkbox-inline">
    <input type="checkbox" value="">Scanner
    </label></li>

    <li>
    <label class="checkbox-inline">
    <input type="checkbox" value="">Barcode Scanner
    </label></li>

    <li>
    <label class="checkbox-inline">
    <input type="checkbox" value="">Others
    </label></li>



    <ul id="software">
    <li>
    <div class="form-group" id="textbox" >
    <label for="softwarerequired">Software Required </label>
    <textarea class="form-control" rows="5" id="software"></textarea>
    </div></li>
    </ul>

    </form>

    </div>
    </div>

    </fieldset>
    </form>

    <div >
     <div class="fill">
        <div class='sign-container'>
        <div class="div1">Form Filled by</div>
        <div class='sign'>&nbsp;</div>


        <div class="div2"> </div>

        <div class="div3">(HR)</div>
        </div>
     </div>

    <div class="sign-box">
    <p id="signbox"> Signature </p>
    <div class="div4"> </div>


     <div class="fill">
        <div class='sign-container'>
        <div class="div1">Form Filled by</div>
        <div class='sign'>&nbsp;</div>


        <div class="div2"> </div>

        <div class="div3">(Admin Manager)</div>
        </div>
     </div>

    <div class="sign-box">
    <p id="signbox"> Signature </p>
    <div class="div4"> </div>

    </div>



    <div class="fill">
        <div class='sign-container'>
        <div class="div1">Form Filled by</div>
        <div class='sign'>&nbsp;</div>


        <div class="div2"> </div>

        <div class="div3">(IT Manager)</div>
        </div>
     </div>

    <div class="sign-box">
    <p id="signbox"> Signature </p>
    <div class="div4"> </div>

    </div>
    </div>

    <div class="Threeform">

    <form>
    <fieldset>
    <legend> User Confirmation </legend>
    <div class="sign-container">
     <div class="div1">User Name</div>
     <div class='sign'>&nbsp;</div>

    <div class="div1">System No</div>
    <div class='sign'>&nbsp;</div>  
    </div>

    <div class="policy-container">
    <div class="div1">Received all the above mentioned facilities and understood international & FGC Cyber policy by
    <div class='sign1'>&nbsp;</div></div>



    </div>

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

    </form>
    </div>

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

plz help me to rectify.

I am not able to connect from form.html page to addtodatabase.php . Notice: Undefined index: firstname in C:\wamp64\www\Form\addtodatabase.php on line 12

Isaac Bennetch
  • 11,830
  • 2
  • 32
  • 43
  • (1) HTML, by itself, can't speak to PHP. However, you're probably wanting to "submit" a form that will then be processed by `addtodatabase.php`? (2) If that's the case then, there should be a `submit` button in the form - [see here](http://php.net/manual/en/tutorial.forms.php). (3) `mysql_*` queries [should no longer be used](http://stackoverflow.com/q/12859942/2298301). (4) Please take a look at [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) or [PDO prepared statements](http://php.net/manual/en/pdo.prepare.php) instead. – Dhruv Saxena Mar 05 '17 at 12:15
  • I have submit button .I have changed it to MySQLi . – Eiman Sadath Assadi Mar 05 '17 at 12:35
  • The submit button belongs to a `form`, so should be placed somewhere before `` – Dhruv Saxena Mar 05 '17 at 15:20
  • button for submit is inside the form . – Eiman Sadath Assadi Mar 05 '17 at 18:18
  • There's clearly something not quite right. You say that you've changed the `mysql_*` functions to `mysqli_*` instead, yet the error message clearly tells you: `Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:\wamp64\www\Form\addtodatabase.php on line 2`. Either your changes are not saved or you're running the code from a location which is different from the one that's being changed. – Dhruv Saxena Mar 05 '17 at 18:24
  • thanks alot it helped with previous suggestions . But i want know y its not loading addtodatabase.php page . – Eiman Sadath Assadi Mar 06 '17 at 08:31

1 Answers1

1

You need to pass 2 parameters! $result = mysqli_query($connect, $query);

Saurabh Sharma
  • 2,422
  • 4
  • 20
  • 41