Очень простая функция вставки, и все же. Это дает некоторые неприятные ошибки ...
Как:
Warning: mysql_query(): Access denied for user '***.'@'***.one.com' (using password: NO) in /customers/***.be/***.be/httpd.www/belastingen/classes/btw.php on line 24 Warning: mysql_query(): A link to the server could not be established in /customers/***.be/***.be/httpd.www/belastingen/classes/btw.php on line 24
А это код:
<?php
if(isset($_POST['submit'])){
$naam = $_POST['name'];
$email = $_POST['email'];
$kind1 = $_POST['kind1'];
$kind2 = $_POST['kind2'];
$kind3 = $_POST['kind3'];
$kind4 = $_POST['kind4'];
$kind5 = $_POST['kind5'];
$captcha = $_POST['captcha'];
if ($captcha == 2){
if (!empty($_POST['name']) && !empty($_POST['email']) && !empty($_POST['kind1'])) {
$insert = "INSERT INTO belastingen (ouder, email, kind1, kind2, kind3, kind4, kind5) VALUES (
'".$naam."',
'".$email."',
'".$kind1."',
'".$kind2."',
'".$kind3."',
'".$kind4."',
'".$kind5."')";
if (!mysql_query($insert)) {
echo "<div class=\"feedback\">query invoeren faalt</div>";
} else {
echo "<div class=\"feedback\">Uw registratie werd goed geregistreerd</div>";
}
} else {
echo "<div class=\"feedback\">falen, niveau 2</div>";
}
} else {
echo "<div class=\"feedback\">captcha probleem</div>";
}
}
?>
И не беспокойтесь о MySQL-инъекции. Добавление, как мы говорим.
Есть мысли об ошибке?
И да, я уверен, что данные для подключения к базе данных верны.
ОБНОВЛЕНИЕ 1
Это мой inc.php
-файл, включенный в начало файла index.php.
<?php
define('MYSQL_HOST', '***.be.mysql');
define('MYSQL_DB', '***');
define('MYSQL_USER', '***');
define('MYSQL_PASSW', '***');
require_once 'classes/dbconnections.php';
require_once 'classes/btw.php';
$_DB = new DBConnection(MYSQL_HOST, MYSQL_DB, MYSQL_USER, MYSQL_PASSW);
?>
ОБНОВЛЕНИЕ 2
Это мой dbconnections.php
-файл
<?php
class DBConnection {
public $host;
public $db;
public $user;
public $password;
private $_connection;
public function __construct($host = null, $db = null, $user = null, $password = null) {
$this->host = $host;
$this->db = $db;
$this->user = $user;
$this->password = $password;
$this->connect();
}
private function connect(){
$this->_connection = mysql_connect($this->host, $this->user, $this->password);
if(!$this->_connection) {
die("An error occured---- while connecting to the database: ".mysql_errno()." - ".mysql_error());
} else{
$selected = mysql_select_db($this->db, $this->_connection);
if(!$selected) {
die("An error occured while connecting to the database: ".mysql_errno()." - ".mysql_error());
}
}
}
public function listing($sql) {
$result = mysql_query($sql, $this->_connection);
while($row=mysql_fetch_array($result)) {
$return[] = $row;
}
return $return;
}
public function select($sql) {
$result = mysql_query($sql, $this->_connection);
return mysql_fetch_array($result);
}
public function insert($sql) {
mysql_query($sql, $this->_connection);
return mysql_affected_rows($this->_connection);
}
public function delete($sql) {
mysql_query($sql, $this->_connection);
return mysql_affected_rows($this->_connection);
}
public function escape($value) {
return mysql_real_escape_string($value);
}
}
?>
ОБНОВЛЕНИЕ 3
Ошибка, которую я получаю при замене тонких, предложенных ниже
Notice: Undefined variable: _DB in /customers/***/***/httpd.www/belastingen/classes/btw.php on line 13 Fatal error: Call to a member function insert() on a non-object in /customers/***/***/httpd.www/belastingen/classes/btw.php on line 13