php - 无法使用 PHP 连接到我的 bplaced.net Mysql 数据库(无错误)

标签 php mysql

我想使用 Ajax (jQuery) 将一些参数从 HTML 文件发送到我的 PHP 文件,该文件也在 bplaced.net 服务器上。几乎一切都很好,我的 Ajax 方法将参数发送到 PHP 文件,PHP 文件接收它们并且还与我的 Mysql 数据库连接。当我尝试插入数据库表时,唯一的问题没有发生(没有错误)表仍然是空的。

<?php
header('Access-Control-Allow-Origin: *');
// Verbindung herstellen //
@$verbindung = mysql_connect("localhost","username","password","database");

//Variablen
$a1 = $_POST["a1"];
$a2 = $_POST["a2"];
$a3 = $_POST["a3"];
$a4 = $_POST["a4"];
$a5 = $_POST["a5"];
$a6 = $_POST["a6"];
$a7 = $_POST["a7"];
$a8 = $_POST["a8"];
$a9 = $_POST["a9"];
$a10 = $_POST["a10"];
$a11 = $_POST["a11"];
$a12 = $_POST["a12"];
$a13 = $_POST["a13"];
$a14 = $_POST["a14"];
$a15 = $_POST["a15"];
$a16 = $_POST["a16"];
$a17 = $_POST["a17"];
$a18 = $_POST["a18"];
$a19 = $_POST["a19"];
$a20 = $_POST["a20"];
$a21 = $_POST["a21"];
$a22 = $_POST["a22"];
$a23 = $_POST["a23"];
$a24 = $_POST["a24"];
$a25 = $_POST["a25"];
$a26 = $_POST["a26"];
$a27 = $_POST["a27"];
$a28 = $_POST["a28"];
$a29 = $_POST["a29"];
$a30 = $_POST["a30"];
$a31 = $_POST["a31"];
$a32 = $_POST["a32"];
$a33 = $_POST["a33"];
$a34 = $_POST["a34"];
$a35 = $_POST["a35"];
$a36 = $_POST["a36"];

// Einfügen
$eintrag = "INSERT INTO test (name) VALUES ('tim')";
$eintragen = mysql_query($eintrag);

if($eintragen) {
  echo "Eintrag war erfolgreich";
} else {
  echo "Fehler beim Speichern";
}

mysql_close($verbindung);
?>

它呼应:“Fehler beim Speichern”。

(PS:其他变量尚未使用)。

最佳答案

Use this code to find out if the Connection is ok:

  try {
    $verbindung =         mysql_connect("localhost","username","password","database");
  } catch (Exception $e) {
    echo 'Exception vorhanden: ',  $e->getMessage(), "\n";
  }

// Code fortsetzen

与这段代码相同,以查明您的插入是否正常工作:

    Try { $eintragen = mysql_query($eintrag);}

关于php - 无法使用 PHP 连接到我的 bplaced.net Mysql 数据库(无错误),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41077255/

相关文章:

php - mysql 的凭据应该放在哪里?

php - jScrollPane - 如何获得轨道的固定宽度

php - codeigniter fatal error 使用 $this 不在对象上下文中

php - MySQL photo like 计数。如何存储和统计照片的数百万个赞?

php - CentOS安装php-mbstring报错

mysql - 使用来自另一个表的条件的 SELECT 语句中的值更新 mysql 字段

php - 将表单电子邮件发送至 .cc 电子邮件

mysql - 如何转义用作列名的保留字? MySQL/创建表

php - MYSQLi 错误 : User already has more than 'max_user_connections' active connections

mysql - Rails 3 Mysql rake 数据库 :create issue