PHP无法保存数据,所有字段都已填充,但出现错误消息

时间:2016-09-17 08:32:30

标签: php html

这是我的表单部分

<form role= "form" action="SaveEmployee.php" method="POST">
                    <div class="form-group">
                      <label for="AddEName" class="col-sm-2 control-label">Name: </label>
                      <div class="col-sm-5">
                        <input type="text" class="form-control" id="AddEName" name="AddEName">
                      </div>
                    </div>
                    <br></br>
                    <div class="form-group">
                      <label for="AddEGender" class="col-sm-2 control-label">Gender: </label>
                      <div class="col-sm-5">
                        <input type="text" class="form-control" id="AddEGender" name="AddEGender">
                      </div>
                    </div>
                    <br></br>
                    <div class="form-group">
                      <label for="AddECoNum" class="col-sm-2 control-label">Contact No: </label>
                      <div class="col-sm-5">
                        <input type="text" class="form-control" id="AddECoNum" name=="AddECoNum">
                      </div>
                    </div>
                    <br></br>
                    <div class="form-group">
                      <label for="AddEEmail" class="col-sm-2 control-label">Email Address: </label>
                      <div class="col-sm-5">
                        <input type="text" class="form-control" id="AddEEmail" name=="AddEEmail">
                      </div>
                    </div>
                    <br></br>
                    <div class="form-group">
                      <label for="AddEID" class="col-sm-2 control-label">IC/Passport No: </label>
                      <div class="col-sm-5">
                        <input type="text" class="form-control" id="AddEID" name="AddEID">
                      </div>
                    </div>
                    <br></br>
                    <div class="form-group">
                      <label for="AddENat" class="col-sm-2 control-label">Nationality: </label>
                      <div class="col-sm-5">
                        <input type="text" class="form-control" id="AddENat" name="AddENat">
                      </div>
                    </div>
                    <br></br>
                    <div class="form-inline">
                      <label for="AddEAdd" class="col-sm-2 control-label">Address: </label>
                      <textarea class="form-control" rows="5" cols="68" id="AddEAdd" name="AddEAdd"></textarea>
                    </div>
                    <br></br>
                    <div class="form-group">
                      <label for="AddESal" class="col-sm-2 control-label">Salary (Monthly): </label>
                      <div class="col-sm-5">
                        <input type="text" class="form-control" id="AddESal" name="AddESal">
                      </div>
                    </div>
                    <br></br>
                    <div class="form-group">
                      <label for="AddEDeg" class="col-sm-2 control-label">Designation: </label>
                      <div class="col-sm-5">
                        <input type="text" class="form-control" id="AddEDeg" name="AddEDeg">
                      </div>
                    </div>
                    <br></br>
                    <button type="submit" class="btn btn" onclick="location.href='SaveEmployee.php';">Save</button>
                    <button type="submit" class="btn btn" onclick="location.href='HomePage.php';">Back</button>
                    </form>

这是我的php部分。

<?php

                  if (isset($_POST['AddEName']))
                  {
                      $AddEName=$_POST['AddEName'];
                      $AddEGender=$_POST['AddEGender'];
                      $AddECoNum=$_POST['AddECoNum'];
                      $AddEEmail=$_POST['AddEEmail'];
                      $AddEID=$_POST['AddEID'];
                      $AddENat=$_POST['AddENat'];
                      $AddEAdd=$_POST['AddEAdd'];
                      $AddESal=$_POST['AddESal'];
                      $AddEDeg=$_POST['AddEDeg'];


                      $SaveEmployee= "INSERT INTO Employee (EName, EGender, ECoNum, EEmail, EID, ENat, EAdd, ESal, EDeg) VALUES ('$AddEName', '$AddEGender','$AddECoNum','$AddEEmail', '$AddEID', '$AddENat', '$AddEAdd', '$AddESal', '$AddEDeg')";

                      if (empty ($_POST['AddEName'])||empty ($_POST['AddEGender'])||empty ($_POST['AddECoNum'])||empty ($_POST['AddEEmail'])||empty ($_POST['AddEID'])||empty ($_POST['AddENat'])||empty ($_POST['AddEAdd'])||empty ($_POST['AddESal'])||empty ($_POST['AddEDeg']))
                        {
                            echo '<div class="callout callout-danger">
                            <h4>Notice!</h4>
                            <p>Unable to save!</p>
                            </div>';
                        }
                        else 
                        {
                            mysql_query($SaveEmployee);

                            echo '<div class="callout callout-success">
                            <h4>Notice!</h4>
                            <p>Employee Saved!.</p>
                            </div>';
                        }


                  }
                  ?>

这是我的问题,我不确定我的代码出了什么问题,一切都是正确的但我无法保存数据,当我点击保存时,它将始终显示&#34;无法保存&#34;消息,即使我填写表格。

有人可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

你正在写你的javascript / ajax吗? 因为在上面的代码中你写了一个函数MatrixB<-data.frame(i=c(1,1,1,2,2,3), j=c(3,4,5,4,5,5), S_i=c(0.87,0.87,0.87,0.49,0.49,0.36), S_j=c(0.36,0.83,0.87,0.83,0.87,0.87)) i j S_i S_j 1 1 3 0.87 0.36 2 1 4 0.87 0.83 3 1 5 0.87 0.87 4 2 4 0.49 0.83 5 2 5 0.49 0.87 6 3 5 0.36 0.87 在表格上

  i j  S_i  S_j  Max
1 1 3 0.87 0.36 0.49
2 1 4 0.87 0.83 0.49
3 1 5 0.87 0.87 0.83
4 2 4 0.49 0.83 0.36
5 2 5 0.49 0.87 0.83
6 3 5 0.36 0.87 0.83

你的javascript / ajax?