Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4622228
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:48:50+00:00 2026-05-22T02:48:50+00:00

A very simple insert function, and yet. It gives some nasty errors… Like: Warning:

  • 0

A very simple insert function, and yet. It gives some nasty errors…

Like:

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

And this is the code:

<?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>";
        }
    }   
?>

And don’t worry about the MySQL-injection. Adding as we speak.
Any thought about the error?
And yes I’m sure the data for connection to the database are correct.

UPDATE 1
This is my inc.php-file, included on top of the index.php file.

<?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);
?>

UPDATE 2
This is my dbconnections.php-file

<?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);
  }

}

?>

UPDATE 3
The error I get when replacing the thins suggested below

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T02:48:51+00:00Added an answer on May 22, 2026 at 2:48 am

    As per our discussion in the comments on your question, try changing things up so that inc.php is required in btw.php; btw.php is required in index.php rather than inc.php; and ‘btw.php` is not required in inc.php. From reading php.net/manual/en/function.include.php, I think this might have to do with scope.

    EDIT:

    First off, the setup you have creates a custom database object class (DBConnection) which is used to interface with the database and execute queries. When you used mysql_query by itself, it did not have a database connection identifier from which to execute the query, since the DBConnection object abstracts that functionality in object methods. That is why you needed to use if (!$_DB->insert($insert)).

    Secondly, and I’m not 100% on this, but essentially core the problem seems to have to do with the code in btw.php not “seeing” the database setup code. This could have been because of two things. First, the $_DB variable was defined after the btw.php code was required, and as a result, when the PHP interpreter parsed btw.php, $_DB had not yet been defined. The order if the requires and the database object definition matter. Secondly, and this is where I am a bit unsure, but I think there is a variable scope/access issue when requiring btw.php from within inc.php (where $_DB is defined) rather than requiring the database setup within btw.php. In other words, you had the code that uses the database object required in the script that defines it, rather than the database setup script (including the database object declaration) required within the code that uses it.

    I hope that makes sense, please let me know if it is still confusing. I tend to have a problem explaining things concisely.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to do a very simple INSERT using VB.NET. For some reason I'm
This very simple code gives me tons of errors: #include <iostream> #include <string> int
I have to run a very simple query like this in SQLite3. INSERT OR
I have a very simple INSERT statement being executed from a PHP script running
Hey all, I am trying to accomplish something very simple yet getting an error
I have a very simple helper function to produce SET statement for traditional plain
Caching in ASP.NET looks like it uses some kind of associative array: // Insert
I have very simple and stupid trouble: std::map<b2Vec2, b2Body*> mTakePoints; mTakePoints.insert(std::make_pair(point, body)); Compiler says:
Here's a very simple question. I have an SP that inserts a row into
Very simple question, is there any cloud server enviroments avaliable these days for us

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.