如何在php中的文本框中显示数据

时间:2016-12-17 12:36:13

标签: php html5 css3

我在这段代码中遇到了问题。当我按下#34;显示按钮"我希望数据库显示在文本框中的数据和"修改"和"删除"按钮工作。 但是在这段代码中,当我按下show按钮时显示错误Notice: Undefined index: first_name,我被困在这段代码中。如何解决这个问题?


    

        include '../../../../database/dbConnection.php';

        //-------------------------------------------
        $row[0]="";
$isSaveDisabled = true;
$isCreateDisabled=false;
$isModifyDiasbled=true;
$isDeleteDisabled=true;


                                if (isset ($_POST['create_button'])) {

                                $isSaveDisabled = false;
                                $isCreateDisabled=true;

                                $sql="select ifnull(max(user_id),10000)+1 from user_master";
                                $res=  mysql_query($sql);
                                $row=  mysql_fetch_array($res);
                                 $row[0];



           }
           if(isset($_POST['modify_button']))
               {

               }
           if(isset($_POST['delete_button']))
               {

               }
        ?>

<!--
        PHP CODE ENDS FROM HERE-------------------------
        -->
        <!--
        BOOTSTRAP START FROM HERE-------------------------
        -->
        <!DOCTYPE html>
        <html>
        <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" href="../../../../bootStrap/css/bootstrap.css">
        <link rel="stylesheet" href="../../../../bootStrap/css/bootstrap.min.css">
        <link rel="stylesheet" href="../../../../css/StyleSheet.css">
        <script src="../../../../js/ValidateKeyPress.js"></script>

        <title></title>
        <script>

</script>
        </head>
        <body>
        <p id="demo"></p>
<!--        <div class="page-header1">
        Hello
        </div>-->
        <div class="container jumbotron  ">
        <div class=" text-center"><h4>USER CREATION</h4></div>

        <form class="form-inline " action="" method="POST" name="myForm">
            <div class="form-group1">

        <label class="control-label" for="ec" id="myID">ENTITY CODE</label>
        <select class="form-control2" name="ecode" id="myID">
        <option value="">SELECT ENTITY CODE</option>   
        <option>DOC</option>
        <option>EMP</option>
        <option>NUR</option>
        <option>ORG</option>
        <option>TEC</option>
        <option>VEN</option>
        </select>
        </div>
        <div class="form-group1">
        <label class="control-label" for="uid">USER ID</label>
        <input type="text" class="form-control2" name="userid" value="<?php echo $row[0];?>">
        </div> 
          <hr>     
        <table class="table1 table-borderless table-responsive">

        <tbody>
<?php

if(isset($_POST['select_button']))
    {
    $qrydatabind='SELECT ecode, first_name, middle_name, last_name, father_name, mother_name,
          number_of_dependents, dob, gender, identification_mark, marital_status, spouse_name, mobile_number,
          email_id, adhar_id, pan_number, passport_number, tin_number, dl_number FROM USER_MASTER ORDER BY user_id DESC 
          LIMIT 1';
                  $results1=  mysql_query($qrydatabind) or die(mysql_error());

                      while( $row =  mysql_fetch_array( $results1 ) ) {

    }
    }
?>
        <tr>

          <th scope="row"></th>
         <td><label class="control-label" for="finame" id="myID1" >FIRST NAME</label></td>
        <td><input value="<?php echo $row["first_name"]; ?>"  type="text" class=" form-control2 input-sm text-uppercase"name="firstname" onkeypress="return allCharacter(event);" ></td>
        <td><label  class="control-label" for="mname">MIDDLE NAME</label></td>
        <td><input type="text" class=" form-control2 input-sm text-uppercase" name="middlename"></td>
        <td><label  class="control-label" for="lname" id="myID2">LAST NAME</label></td>
        <td><input type="text" class="  form-control2 input-sm text-uppercase" name="lastname" onkeypress="return allCharacter(event);"></td>
        </tr>
        <tr>
          <th scope="row"></th>
          <td><label  class="control-label" for="fname">FATHER NAME</label></td>
        <td><input type="text" class=" form-control2 input-sm text-uppercase" name="fathername"></td>
          <td><label  class="control-label" for="moname">MOTHER NAME</label></td>
        <td><input type="text" class="form-control2 input-sm text-uppercase" name="mothername"></td>
        <td><label  class="control-label" for="nod">NO.OF DEPENDENTS</label></td>
        <td><input type="text" class="form-control2 input-sm text-uppercase" name="nod"></td>
        </tr>
        <tr>
          <th scope="row"></th>
          <td><label  class="control-label" for="dob" id="myID3">D.O.B</label></td>
          <td><input type="text" class=" form-control2 input-sm text-uppercase" name="dob" placeholder="DD/MM/YYYY"  id="myID3" ></td>
        <td><label  class="control-label" for="gen" id="myID4">GENDER</label></td>

        <td><select id="myID4" class="form-control2" name="gender">
        <option value="">SELECT GENDER</option> 
        <option>M</option>
        <option>F</option>
        <option>o</option>

        </select></td>
        <td><label  class="control-label" for="idm">IDENTIFICATION MARK</label></td>
        <td><input type="text" class=" form-control2 input-sm text-uppercase" name="idmark"></td>
        </tr>
        <tr>
          <th scope="row"></th>
          <td><label  class="control-label" for="ms">MARITAL STATUS</label></td>

        <td><select class=" form-control2" name="mstatus">
        <option value="">SELECT STATUS</option> 
        <option>M</option>
        <option>U</option>


        </select></td>
        <td><label  class="control-label" for="sname">SPOUSE NAME</label></td>
        <td><input type="text" class=" form-control2 input-sm text-uppercase" name="spname"></td>
        <td><label  class="control-label" for="mno" id="myID5">MOBILE NO.</label></td>
        <td><input type="text" class=" form-control2 input-sm text-uppercase" name="mobileno" maxlength="12" onkeypress="return allnumeric(event);"></td>
        </tr>
        <tr>
          <th scope="row"></th>
          <td><label  class="control-label" for="em">EMAIL-ID</label></td>
          <td><input  id="myID6" type="text" class="form-control2 input-sm text-uppercase" name="email" placeholder="sample@gmail.com"></td>
        <td><label  class="control-label" for="adhar">ADHAR-ID</label></td>
        <td><input type="text" class="form-control2 input-sm text-uppercase" name="adharid"></td>
        <td><label  class="control-label" for="paname">PAN NUMBER</label></td>
        <td><input type="text" class=" form-control2 input-sm text-uppercase" name="pannumber"></td>
        </tr>
        <tr>
          <th scope="row"></th>
          <td><label  class="control-label" for="passno">PASSPORT NO.</label></td>
        <td><input type="text" class="form-control2 input-sm text-uppercase" name="passportno"></td>
        <td><label  class="control-label" for="tno">TIN NUMBER</label></td>
        <td><input type="text" class=" form-control2 input-sm text-uppercase" name="tinnumber"></td>
        <td><label  class="control-label" for="dno">DL NUMBER</label></td>
        <td><input type="text" class=" form-control2 input-sm text-uppercase" name="dlnumber"></td>
        </tr>


        </tbody>
        </table>


          <div class="btn-group-sm2 text-center">
        <button type="submit" class="btn btn-primary"  name="create_button" <?php echo $isCreateDisabled?'disabled':'';?>>CREATE</button>

        <?php
  if($isCreateDisabled) {
    echo '<script>document.getElementById("myID").style.color = "red";</script>';
    echo '<script>document.getElementById("myID1").style.color = "#ff0000";</script>';
    echo '<script>document.getElementById("myID2").style.color = "#ff0000";</script>';
    echo '<script>document.getElementById("myID3").style.color = "#ff0000";</script>';
    echo '<script>document.getElementById("myID4").style.color = "#ff0000";</script>';
    echo '<script>document.getElementById("myID5").style.color = "#ff0000";</script>'; 
    echo '<script>document.getElementById("myID6").style.color = "#ff0000";</script>';    

  }
?>
        <button type="submit" class="btn btn-primary" name="modify_button"<?php echo $isModifyDiasbled?'disabled':'';?>>MODIFY</button>
        <button type="submit" class="btn btn-primary" name="delete_button" <?php echo $isDeleteDisabled?'disabled':'';?>>DELETE</button>
        <button type="submit" class="btn btn-primary" name="clear_button">CLEAR</button>
        <button type="submit" class="btn btn-primary " name="save_button" <?php echo $isSaveDisabled?'disabled':''; ?> onclick="return validateForm();">SAVE</button>
        <button type="submit" class="btn btn-primary" name="exit_button">EXIT</button>
        <button type="submit" class="btn btn-default text-right" name="search_button">SEARCH</button>
           <button type="submit" class="btn btn-default text-right" name="select_button">SHOW</button>
        </div>
        </form>

        </div>

      </tbody>

      <div class="table-responsive">
          <table class="table">


               <?php
        if(isset($_POST['save_button'])){
        $isCreateDisabled=false;
                if(isset($_POST['ecode']) && isset($_POST['firstname'])&& isset($_POST['middlename'])&& isset($_POST['lastname'])
                && isset($_POST['fathername'])&& isset($_POST['mothername'])&& isset($_POST['nod']) && isset($_POST['dob'])
                && isset($_POST['gender'])&& isset($_POST['idmark'])&& isset($_POST['mstatus'])&& isset($_POST['spname'])
                && isset($_POST['mobileno'])&& isset($_POST['email'])&& isset($_POST['adharid'])&& isset($_POST['pannumber'])
                && isset($_POST['passportno'])&& isset($_POST['tinnumber'])&& isset($_POST['dlnumber']))
                   {
                           $ecode=$_POST['ecode']; $first_name=$_POST['firstname']; $middle_name=$_POST['middlename'];
                           $last_name=$_POST['lastname']; $father_name=$_POST['fathername']; $mother_name=$_POST['mothername'];  
                           $number_of_dependents=$_POST['nod'];  $dob=$_POST['dob']; $gender=$_POST['gender'];
                           $identification_mark=$_POST['idmark']; $marital_status=$_POST['mstatus'];
                           $spouse_name=$_POST['spname']; $mobile_number=$_POST['mobileno']; $email_id=$_POST['email'];
                           $adhar_id=$_POST['adharid'];$pan_number=$_POST['pannumber'];  $passport_number=$_POST['passportno'];
                           $tin_number=$_POST['tinnumber']; $dl_number=$_POST['dlnumber'];


                   }

                                  $qry="insert into user_master(ecode, first_name, middle_name, last_name, father_name, mother_name,
                                  number_of_dependents, dob, gender, identification_mark, marital_status, spouse_name, mobile_number,
                                  email_id, adhar_id, pan_number, passport_number, tin_number, dl_number)
                                  VALUES('$ecode','$first_name','$middle_name','$last_name','$father_name','$mother_name',
                                      '$number_of_dependents',str_to_date('$dob','%d/%m/%Y'),'$gender','$identification_mark','$marital_status',
                                          '$spouse_name','$mobile_number','$email_id','$adhar_id','$pan_number',
                                              '$passport_number','$tin_number','$dl_number')";
                           $resultss=  mysql_query($qry) or die(mysql_error());
                           if($resultss)
                               {
                               echo "<script>
                                      alert('SuccessFully');
                                        </script>";

                               }
                               else
                                   {
                                   return "Error...! Not Inserted.";
                                   }
          $qrydatabind='SELECT ecode, first_name, middle_name, last_name, father_name, mother_name,
          number_of_dependents, dob, gender, identification_mark, marital_status, spouse_name, mobile_number,
          email_id, adhar_id, pan_number, passport_number, tin_number, dl_number FROM USER_MASTER ORDER BY user_id DESC 
          LIMIT 1';
                  $results=  mysql_query($qrydatabind) or die(mysql_error());

                      while( $row =  mysql_fetch_array( $results ) ) {
                        echo
            "
                <div class='table-responsive'>
<table  border='1' style= 'background-color: #84ed86; color: #761a9b;  ' >
      <thead>
                <tr>
            <th></th>
              <th>Entity Code</th>
              <th>User Id</th> <th>User Name</th> <th>Father Name</th>  <th>Mother Name</th>  <th>No.Of Dependents</th>
              <th>D.O.B</th> <th>GENDER</th> <th>Id Mark</th> <th>MARITAL STATUS</th>  <th>SPOUSE NAME</th>
              <th>Mob. Number</th> <th>E-Id</th> <th>ADHAR-ID</th> <th>PAN-No.</th> <th>PASSPORT-No.</th>
               <th>TIN-NO.</th> <th>DL-No.</th>
            </tr>
                </thead>

                      <tr >        

                        <td> </td> 
                        <td>{$row['ecode']}</td> <td> echo $row[0];</td>
                        <td>{$row['first_name']} {$row['middle_name']} {$row['last_name']}</td>             
                        <td>{$row['father_name']}</td> <td>{$row['mother_name']}</td>
                        <td>{$row['number_of_dependents']}</td> <td>{$row['dob']}</td>
                        <td>{$row['gender']}</td> <td>{$row['identification_mark']}</td>
                        <td>{$row['marital_status']}</td> <td>{$row['spouse_name']}</td>
                        <td>{$row['mobile_number']}</td> <td>{$row['email_id']}</td>
                        <td>{$row['adhar_id']}</td>  <td>{$row['pan_number']}</td>
                        <td>{$row['passport_number']}</td> <td>{$row['tin_number']}</td>
                        <td>{$row['dl_number']}</td>


            </tr> </table>  
              </div>";
        }}


        ?>
    </table>

      </div>

        </body>
        </html>

1 个答案:

答案 0 :(得分:0)

如果编辑和删除工作意味着您的select语句错误。也许你没有在select语句中正确声明你的字段。我先看看。当我的sql出错时我做的是打开一个sql会话并尝试直接从sql编辑器执行查询。

此外,

你为什么使用限制1?您正在获取数组的记录结果,但是您将查询限制为一行?

修改

您是否必须选择user_id才能使用ORDER BY?您所要做的就是将user_id添加到select语句