user7516386
user7516386

Reputation:

if(isset($_POST["submit"]) not working

The isset function is not working on this page however its working on another page. I want to edit my database which is why I have created this but I can't get the values of the text fields just because the isset is not working.

Here is the code

<?php 

$link = mysqli_connect("localhost","root","","officedb");

if(!$link)
{
    echo"Not connected";
}



$query = "SELECT * from items";

$result = mysqli_query($link,$query);

    if(!$result)
    {
        echo"Not selected";
    }



    if(isset($_POST["submit"])){

        echo "Hello";

    }





?>

<html>


    <head>

     <link rel="stylesheet" href="bootstrap-3.3.7-dist/css/bootstrap.min.css" >


        <style>

        .lb
            {
                background-color:#ADD8E6;
                text-align: center;
            }

            .tl
            {
                text-align: center;
            }

            .disapp
            {
                display:none;
            }


        </style>


        <script>

            function divshow(){

              if(document.getElementById("entryname").value == "Name")
                  {
                      document.getElementById("nameed").style.display = 'block';
                       document.getElementById("nsned").style.display = 'none';
                       document.getElementById("quned").style.display = 'none';

                  }

                if(document.getElementById("entryname").value == "NSN/Part")
                  {
                      document.getElementById("nameed").style.display = 'none';
                      document.getElementById("nsned").style.display = 'block';
                       document.getElementById("quned").style.display = 'none';
                  }

                if(document.getElementById("entryname").value == "Quantity")
                  {
                      document.getElementById("nameed").style.display = 'none';
                      document.getElementById("nsned").style.display = 'none';
                       document.getElementById("quned").style.display = 'block';
                  }
            };


        </script>





    </head>


<body>

    <div class="container">
    <table class="table table-hover">
    <tr>
    <th class="lb" >Serial #</th>
        <th class="lb" >Name</th>
        <th class="lb" >NSN/part</th>
        <th class="lb" >Quantity</th>


 <?php       
while($row = mysqli_fetch_array($result))
{
?> 

        <tr>

            <td class="tl"><?php echo $row["S.NO"]; ?></td>
            <td class="tl"><?php echo $row["Name"]; ?></td>
            <td class="tl"><?php echo $row["NSN/Part"]; ?></td>
            <td class="tl"><?php echo $row["Quantity"]; ?></td>

        </tr>

        <?php } ?>

    </table>




             <div class="border" style="border:1px solid grey;border-radius:6px;width:50%;margin-left:25%">

            <div class="row" style="margin-top:7%;">




                <div class="col-lg-4 col-lg-offset-3" style="margin-left:33%;">


            <form method="POST">

  <label>Select Item Serial #:</label>

  <select class="form-control">



      <?php

       $sql = "SELECT * from items";

      $newar=mysqli_query($link,$sql);



      while($edit = mysqli_fetch_array($newar)){  ?>

      <option value = <?php $edit[0]; ?> > <?php  echo $edit[0]; }  ?> </option>



  </select>

                  <label style="margin-top:7%;">Select entry</label>
  <select class="form-control" name="entryname" onchange="divshow()">
    <option value="Name">Name</option>
    <option value="NSN/Part">NSN/Part</option>
      <option value="Quantity">Quantity</option>
  </select>





                 <div id="nameed" >
        <input type="text" placeholder="Enter New Name" class="form-control"  required name="namtxt"  style="margin-top:16%;" />
        </div>

        <div id="nsned" class="disapp" >
        <input type="text" placeholder="Enter New NSN/Part" class="form-control"  required name="nsntxt"  style="margin-top:16%;" />
        </div>

        <div id="quned" class="disapp" >
        <input type="text" placeholder="Enter New Quantity" class="form-control"  required name="quntxt"  style="margin-top:16%;" />
        </div>



                <div class="text-center">

                <input type="submit" name="submit" style="width:70%;margin-top:20%;" class="btn btn-success btn-md" value="Edit" /> 

                </div>



                    </form>


                </div>

                    </div> 

                </div>




    </div>
</body>






</html>

Upvotes: 1

Views: 386

Answers (1)

Amit Gaud
Amit Gaud

Reputation: 766

problem is here this is required field but it not displaying in front end and when you submitting the form the from is not submitted it produce java script error in code so first solve this

        <div id="nsned" class="disapp" >
        <input type="text" placeholder="Enter New NSN/Part" class="form-control"  required name="nsntxt"  style="margin-top:16%;" />
        </div>

        <div id="quned" class="disapp" >
        <input type="text" placeholder="Enter New Quantity" class="form-control"  required name="quntxt"  style="margin-top:16%;" />
        </div>

Upvotes: 1

Related Questions