我一直在为我的网站创建一个数据库。我尝试从我的实时网站插入数据库时遇到错误。我不是100%清楚一切是如何工作的,并且不确定在修复此错误时从哪里开始。
我想在安装/设置所有内容时可能会遗漏一些内容,所以我会列出我设置它的步骤。
我已经在线跟踪了许多教程(并且已经查看了堆栈溢出)来设置xampp,phpMyAdmin和MySQL,但仍无法找到解决方案。
以下是来自contact.php的PHP代码(您看到“已移除”的任何地方,出于安全原因已删除实际数据)。
if (isset($_POST['submit'])){
define('DB_NAME', 'removed');
define('DB_USER', 'removed');
define('DB_PW', 'removed');
define('DB_HOST', '127.0.0.1');
if(!$link = mysqli_connect(DB_HOST, DB_USER, DB_PW, DB_NAME)){
echo "Unable to connect to database - Error: " . mysqli_error();
} else {
echo "Succesful";
}
//Name
$FName = $_POST['FName'];
$FName = mysqli_real_escape_string($link, $FName);
$LName = $_POST['LName'];
$LName = mysqli_real_escape_string($link, $LName);
$Company = $_POST['Company'];
$Company = mysqli_real_escape_string($link, $Company);
//Phone
$Phone1 = $_POST['Phone1'];
$Fax = $_POST['Fax'];
//Address
$Street = $_POST['Street'];
$Street = mysqli_real_escape_string($link, $Street);
$City = $_POST['City'];
$City = mysqli_real_escape_string($link, $City);
$State = $_POST['State'];
$State = mysqli_real_escape_string($link, $State);
$Zip = $_POST['Zip'];
$Zip = mysqli_real_escape_string($link, $Zip);
$Country = $_POST['Country'];
$Country = mysqli_real_escape_string($link, $Country);
//Message
$Message = $_POST['Message'];
$Message = mysqli_real_escape_string($link, $Message);
//Email
$Email = $_POST['Email'];
$Email = mysqli_real_escape_string($link, $Email);
//Email
$Email2 = $_POST['Email2'];
$Email2 = mysqli_real_escape_string($link, $Email2);
$sqlInsert = "INSERT INTO `removed`.`removed`(`ID`, `FName`, `LName`, `Company`, `Phone`, `Fax`, `Street`, `City`, `State`, `Country`, `Zipcode`, `Email`, `SEmail`, `Message`) VALUES (NULL, '".$FName."', '".$LName."', '".$Company."', '".$Phone1."', '".$Fax."', '".$Street."', '".$City."', '".$State."', '".$Country."', '".$Zipcode."', '".$Email."', '".$Email2."', '".$Message."')";
if(!mysqli_real_query($link, $sqlInsert)){
echo "Failed To Post To Database";
} else {
mysqli_close($link);
echo "Posted To Database!" . mysqli_error();
}
提交表单时,“无法连接到数据库 - 错误:无法发布到数据库”没有出现mysqli错误。
任何帮助,想法或任何事情都非常感激我没有想法解决这个问题。