提交到mysql数据库的问题

时间:2018-04-24 04:01:55

标签: php mysql database

刚刚将我的网站迁移到新网址。除了我不能再向MySQL数据库提交查询外,一切顺利。我在PHPmyAdmin中重建了我的表,并且可以像以前一样访问它们来检索数据。但提交被破坏了。

<?php
  include('./sqlFunctions/sqlFunctions.php');
//link to mySQL database
  $link = linkDB();

//On Submit execute the following code
  if($_POST['submit']){
  //pass link to submitDB().  If errors encounted script will die and pass the errors back.
    $error = submitDB($link);

    if($error){
  //pass errors from php to session Storage to display on reload
      echo "<script>alert( 'Error Encountered' );</script>";
      die();
    }
  }
?>

最后的警报脚本会触发每次运行。所以我假设我的SQL查询有问题。查看函数submitDB(),我们看到......

   <?php
      function submitDB($link){
    //variable to hold relavent error messages.  Set to false
      $error = false;

      //Establish Variables from Post
        $title = $_POST['title'];  //etc

      //Check data fields
        if(!$title){
          $error .= $missingTitle;
        }else{
          $title = filter_var($title, FILTER_SANITIZE_STRING);
          $title = mysqli_real_escape_string($link, $title); //etc
        }
        if($error){
            echo "<script>alert( 'Never Fires');</script>";
          return $error;
          die();
        }

        echo "<script>alert( 'This Alert Fires' );</script>";

        //set up our query
        $sql = "INSERT INTO shelters (title, lat, lng, pName, pEmail, pPhone, pContactPub,
        type, oName, oEmail, oPhone, oContactPub, description, descriptionPub)
        VALUES ('$title', '$lat', '$lng', '$pName', '$pEmail', '$pPhone', '$pContactPub',
        '$type', '$oName', '$oEmail', '$oPhone', '$oContactPub', '$description', '$descriptionPub')";

        if ($link->query($sql) === true) {
           echo "<script>alert( 'This Alert Never Fires' );</script>";
           echo '<script>window.location = "'. '../auxPages/mapOfferShelterSuccess.html' .'";</script>';
        } 
        else {
            echo "<script>alert( 'This Alert Always Fires' );</script>";
            $error = $link->error;
            return $error;
        }
      }
    ?>

最后,看起来$ link-&gt;查询($ sql)失败了。但$ sql看起来不错。 使用linkDB()链接到我的数据库后,mysqli_error($ link)也不会返回任何错误。

$link->query($sql)的错误是:

  

'字段列表

中的未知列'pContactPub'

以下是该功能......

function linkDB(){
   $link = new mysqli(SERVER_NAME, USER_NAME, PWD, DB_NAME);
// Check connection
   if ($link->connect_error) {
     die("Connection failed: " . $link->connect_error);
   }
  return $link;
    }

任何想法?我一整天都在撞墙。

0 个答案:

没有答案