刚把我的网站迁移到一个新的网址。一切都很顺利,只是我不能再向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->query($sql)失败了。但是$sql看起来不错。mysqli\u error($link)在使用链接到我的数据库后也不会返回任何错误 linkDB()
.
的错误 $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;
}
有什么想法吗?我整天把头撞在墙上。
暂无答案!
目前还没有任何答案,快来回答吧!